Thursday, 9 May 2019

php - SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

I am writing an android app in b4a and connecting to my web server by a php file. The app was OK until I changed my web host and now i have this error in my code when I run sql command. The phonenumber, code, time, and date are varchar. I even tested as int but no luck.





INSERT INTO TempCodes(ID, PhoneNumber, Code, Time, Date)
VALUES (Null, \'9219142132\', \'835677\', \' 23:09:23 \', \'
2019/03/28 \')\nYou have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '\'9219142132\', \'835677\', \' 23:09:23 \', \' 2019/03/28
\')' at line 1





This is my sql command:



"INSERT INTO `TempCodes`(`ID`, `PhoneNumber`, `Code`, `Time`, `Date`) VALUES (Null, '" & txtPhoneNumber.Text & "', '" & TempCode & "', '" & xTime & "', '" & xDate & "')"


I also removed " ` " from my variables and still nothing!



$databasehost = "host";
$databasename = "databse";
$databaseusername ="user";

$databasepassword = "pass";

$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename);// or die(mysqli_error($con));

error_reporting(0);

mysqli_set_charset ($con , "utf8");
//$query = file_get_contents("php://input");

// $query = $mcrypt->decrypt($query);

$sth = mysqli_query($con, $query);

//echo $query;

if (mysqli_errno($con)) {
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysqli_error($con);
}
else

{
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
$res = json_encode($rows);
echo $res;
mysqli_free_result($sth);
}
mysqli_close($con);



this is the php code i use



i am in deep trouble here, please help !!!!

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...