Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

SQL query's in PHP

Started by Dracodev Jul 5, 2004 at 10:39 AM 3 replies 450+ views
Original Post
Dracodev
Dracodev
have two statements in my php code, an INSERT INTO and a UPDATE query, my problem is that the INSERT INTO works and the UPDATE query does'nt. the following are my two query's $add_query = "INSERT INTO phonebook ( owner , phone_name , phone_number ) VALUES ('$second_ent', '$third_ent', '$fourth_ent')"; mysql_query ($add_query); ////////////////////////////////// $edit_query = "UPDATE 'phonebook' SET phone_number = '$fifth_ent' WHERE phone_name = '$fourth_ent'"; mysql_query ($edit_query); i'm reasonably confident that both query's are well formed, am bebinning to think that problem may be server side perhaps??? anyone have any ideas!!!!
Kylotan
Kylotan
Are you checking return values, and the error code (mysql_error or something like that)? How about the content of the query string after it's parsed and before it's sent to the database?
acraig
acraig
A simple way to check is to use the die function

mysql_query ($add_query)
or die("Query Error : " . mysql_error());

---------
Andrew
Nik02
Nik02
If I'm not mistaken, '$fifth_ent' and '$fourth_ent' inside the SQL statement are parsed as strings instead of the php variables that they symbolize in code.

Therefore, the following might work:
$edit_query = "UPDATE 'phonebook' SET phone_number = '" . $fifth_ent . "' WHERE phone_name = '" . $fourth_ent . "'"; 

so that the actual values behind the variables get inserted to the query string.

If I'm correct in my logic, your first query would fail too - but it would just insert the variable names to the current cursor, instead of the values (which, I assume, you would want it to do). It would seem to run alright, but the results would be wrong.

Please let us know if this works,
-Nik
Niko Suni
Dracodev
Dracodev

Nik02 never tried your suggested code as i used kylotan's suggestion to use mysql_error() to return the sql error ;-)
the query now looks this
$edit_query = "UPDATE phonebook SET phone_number = $fifth_ent WHERE phone_name = '$fourth_ent' AND owner = '$second_ent' AND phone_number = '$third_ent'"
and it works fine


thanks for the help everyone
Kev

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.