Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update where id=$id

Tags:

sql

php

mysql

I have this query to submit data into the database:

$sql = "UPDATE table SET user='$user', name='$name' where id ='$id'";

the id will be obtained via url EX localhost/index.php?id=123

$id=$_GET['id']

The query will not work correctly; the data will not update. If I write :

$sql = "UPDATE table SET user='$user', name='$name' where id ='123'";

It works fine.

If I echo the ID it will show the correct result, 123.

Where is the problem?

like image 434
Geme Avatar asked Dec 03 '22 00:12

Geme


1 Answers

run ALL your queries the way you can get the error message along with erroneous query.
so, at least this way

$sql = "UPDATE table SET user='$user', name='$name' where id ='$id'";
$res = mysql_query($sql) or trigger_error(mysql_error()." in ".$sql);

and it will tell you where is the problem.

It is WAY more convenient, precise and faster than asking questions here.

like image 154
Your Common Sense Avatar answered Dec 04 '22 12:12

Your Common Sense