1

Currently I am having problem running my code in live server even though i can run it in my localhost.

    if($con->connect_error){
    $response['success'] =0;
    $response['message'] ='could not connect to database';
    print(json_encode($response));
    die(print(json_encode($response)));
}

$response['success'] =1;
$response['message'] ='successfully connected to the database';
print(json_encode($response));


$depart = $_GET['depart'];
$destination = $_GET['destination'];
$sql = "INSERT INTO request (dateNtime, depart, destination, status) VALUES (now(),$depart,$destination,0)"; 
$mysql=mysqli_query($con,$sql);

if($mysql)
{
    echo "successfully";
}
else
{
    echo mysqli_error($con);
}

mysqli_close($con);

Currently this is the error I am getting running this code in live server:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'users\',0)' at line 1 

May I know what is the cause of this error?

DHP_07
  • 97
  • 1
  • 9
  • **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jun 22 '15 at 08:56

2 Answers2

1

From the php docs, and your error it seems mysqli_error() requests the connection as a parameter, change it to mysqli_error($con) and it should work, from there on you can see what is causing it to error.

Gerton
  • 676
  • 3
  • 14
  • Thanks for you for your comment. I have edited my question as you said. Now, I am getting a different error as stated above. Why does that error means? Is it related to MySQL version problem? – DHP_07 Jun 22 '15 at 08:41
  • 1
    @DHP_07 — You now have a different problem. You should accept this answer and ask a new question, not change the question so this answer no longer makes any sense. – Quentin Jun 22 '15 at 08:57
0

After you create your query do echo $sql; And update the question with what you get. Probably you'll see that your $destination is wrong but I can't be sure since I don't know what your table looks like. Please also include the result from DESC request if you run that in mysql.

MyGGaN
  • 1,766
  • 3
  • 30
  • 41