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? Quote 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. Quote 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 Quote 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/50866-variable-in-mysql-query/#findComment-250181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.