从PHP中发布数据并插入表格[关闭]

从PHP中发布数据并插入表格[关闭]

问题描述:

I am getting data from iphone using php but when i insert post data in table it gives error

   mysql_select_db("emriphone", $con);

   $providernpi=$_POST['ProviderNPI'];
  $patienid=$_POST['PatientID'];
  $fileurl=$_POST['FileURL'];
 $filetype=$_POST['FileTYPE'];
 $datasynid=$_POST['DataSynID'];





$query = "INSERT into AppointmentDataSync      (ProviderNPI,PatientID,FileURL,FileType,DataSyncID) VALUES('$providernpi','$patientid','$fileurl','$filetype','$datasynid')"

 $con = mysql_query($query,$con);
$cnt  = mysql_num_rows($con);
echo($providernpi)
  ?>

I think your query statement will be like this

$query = "INSERT into AppointmentDataSync      (ProviderNPI,PatientID,FileURL,FileType,DataSyncID) VALUES('".$providernpi."','".$patientid."','".$fileurl."','".$filetype."','".$datasynid."')";

EDIT

mysql_query($query);
printf("Records inserted: %d
", mysql_affected_rows());

You're missing a few semicolons, for example after the $query = ... and echo(...) statements. A syntax error always means there's something wrong with how you wrote the code, not with the functionality of the code. Just looking carefully at the area around the line number given in the error messages solves most of them.

As for your other problem: mysql_num_rows() complaining about its argument not being a resource means your query has gone wrong. You should check whether the query was executed successfully ($con will evaluate to true then) and if not, check mysql_error() to get an error message.

By the way, your code is wide open to SQL injection. An attacker could insert some unexpected stuff in the POST parameters and your entire database will be leaked or manipulated in a matter of seconds.