HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/xampp/htdocs/myapi/postTestDB.php
<?php
// Get the JSON data sent from the client


$po= $_GET['po'];
$company= $_GET['co'];
$mL= $_GET['mL'];
$ma= $_GET['ma'];
$mb= $_GET['mb'];
$sn= $_GET['sn'];

$json = file_get_contents('php://input');

// Decode JSON to PHP array
$data = json_decode($json, true);

// Process the data
if ($data !== null) {
    // Access the JSON values
	$dStr = $data['prex'];
    $patch1 = $data['patch1'];
$myFile ="../FograCT1/upload/".$dStr;   
//$myFile =$dStr;  
//$myFile ="pptest.txt";                
$fvcc = fopen($myFile, 'a') or die("can't open file");
fwrite($fvcc, $patch1);
fclose($fvcc);

    // Perform actions with the data (e.g., save to a database, perform operations, etc.)
    // Example: Insert data into a database
    // Your database connection code here...
    // $mysqli = new mysqli("localhost", "username", "password", "database");
    // $query = "INSERT INTO your_table_name (name, age, email) VALUES ('$name', '$age', '$email')";
    // $mysqli->query($query);


//$sn="na";
 $servername = "127.0.0.1";
$username = "root";
$password = "fredsql";
$DBNAME = "tvicheck-st";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";


if( !mysqli_select_db($conn, $DBNAME)) {
  die ("無法選擇資料庫");
}
mysqli_query( $conn, "SET NAMES 'utf8'");



		$querys = "select po from spotreport where (po='$po'and company='$company') ORDER BY id DESC LIMIT 1 ";
		//echo $querys."<br>";
		$results =  mysqli_query($conn, $querys);
		$num = mysqli_num_rows( $results);
		
	if ($num > 0 )
	{
		echo json_encode(array('message' => 'Job id exist!'));
	}
	else {
			$queryi = "INSERT INTO spotreport (po, sn,company,ddate, stdL,stda, stdb ) VALUES( '$po','$sn','$company',NOW(),'$mL', '$ma','$mb')";

			$resultsi =   mysqli_query($conn, $queryi);
		
		 echo json_encode(array('message' => 'Data received and processed successfully'));
	}

	//echo json_encode(array('message' => 'Data received and processed successfully'));
    // Respond back to the client (optional)
   
} else {
    // Respond with an error message if JSON data is invalid
    echo json_encode(array('message' => 'Invalid JSON data'));
}
?>