grantypap Posted May 10, 2007 Share Posted May 10, 2007 1 last question guys, im trying to delete a row from my table but i want to select the table depending on a variable value. this is what i've got and i dont understand whats wrong with it! mysql_query("delete from '$Table' where Q_ID='$Q_ID' and Ans='$Delete'"); any ideas? Link to comment https://forums.phpfreaks.com/topic/50866-variable-in-mysql-query/ Share on other sites More sharing options...
per1os Posted May 10, 2007 Share Posted May 10, 2007 mysql_query("delete from `$Table` where Q_ID='$Q_ID' and Ans='$Delete'"); For column and table names you need to use the back ticks ( ` ) to surround them not single quotes ( ' ) those are for the values. Link to comment https://forums.phpfreaks.com/topic/50866-variable-in-mysql-query/#findComment-250176 Share on other sites More sharing options...
grantypap Posted May 10, 2007 Author Share Posted May 10, 2007 ah ok, cheers mate Link to comment https://forums.phpfreaks.com/topic/50866-variable-in-mysql-query/#findComment-250178 Share on other sites More sharing options...
Barand Posted May 10, 2007 Share Posted May 10, 2007 As a general note, when a query doesn't work try a bit of debugging 1 ) put the query string into a variable so it can be echo'd if it fails $sql = "delete from '$Table' where Q_ID='$Q_ID' and Ans='$Delete'"; 2 ) when you call the query, check for errors mysql_query($sql) or die (mysql_error() . "<p>$sql</p>"); Link to comment https://forums.phpfreaks.com/topic/50866-variable-in-mysql-query/#findComment-250181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.