Vyizis Posted March 20, 2007 Share Posted March 20, 2007 I am trying to use php to delete rows for a mysql database table, i am using the following code with $journeyIDToUse being a number that represents a automaticly incrementing primary key. $toDelete = "DELETE FROM journeyData WHERE journeyID='$journeyIDToUse'"; mysql_query($toDelete); This fails to delete the row. I have tried changing $journeyIDToUse to a number and that worked so i thought that the variable might be at fault but the following query works so that rules that out $searchString = "SELECT * FROM journeyData WHERE journeyID='$journeyIDToUse'"; $result = mysql_query($searchString); $row = mysql_fetch_array($result); I cant work out what is happening here so any help will be more than appriciated. Thanks Vyizis Link to comment https://forums.phpfreaks.com/topic/43414-trying-to-delete-rows/ Share on other sites More sharing options...
Glyde Posted March 20, 2007 Share Posted March 20, 2007 Always check variables using a simple print method. print $journeyIDToUse; That would be step 1. Step 2 is to ensure that the number for which $journeyIDToUse is set to actually corresponds to a row in the table Link to comment https://forums.phpfreaks.com/topic/43414-trying-to-delete-rows/#findComment-210861 Share on other sites More sharing options...
Vyizis Posted March 20, 2007 Author Share Posted March 20, 2007 I get the right number and the number does corrispond to a row of the table, this is the first thing i checked. Link to comment https://forums.phpfreaks.com/topic/43414-trying-to-delete-rows/#findComment-210872 Share on other sites More sharing options...
Psycho Posted March 20, 2007 Share Posted March 20, 2007 You should also always have error handling when running queries. Try this: $toDelete = "DELETE FROM journeyData WHERE journeyID='$journeyIDToUse'"; mysql_query($toDelete) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/43414-trying-to-delete-rows/#findComment-210880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.