jeaker Posted May 2, 2007 Share Posted May 2, 2007 I have a little problem. I have the below code that gives a list box... <?php // Query the teacher table and load all of the records // into an array. $sql = 'SELECT * FROM teacher'; $res = mysql_query($sql) or die(mysql_error()); while ($rec = mysql_fetch_assoc($res)) $fname[] = $rec; echo '<SELECT name="fname">'; echo "<option></option>\n"; foreach ($fname as $f) echo "<OPTION>{$f['fname']} </OPTION>\n"; echo '</SELECT>'; ?> It list the First name of some teachers. The user is supposed to be able to click DELETE and run the code below.... <?php include 'library/config.php'; include 'library/opendb.php'; $fname=$_POST['fname']; $sql = "DELETE FROM teacher WHERE fname = '$fname'"; mysql_query($query) or die('Error, query failed'); echo "<br>Teacher $fname deleted<br>"; ?> That code is supposed to delete the entire record wherever it finds that first name in the the table 'teacher'. However I continue to get the error "Error, query failed". I know it is probably an error in my sql statement somewhere, but I have been trying for the past 3 hours to get something to work and I have nothing. If anyone has any advice it would be greatly appreciated. Thanks so much!!! Quote Link to comment https://forums.phpfreaks.com/topic/49619-solved-error-in-code-can-anyone-be-my-hero-and-spot-it/ Share on other sites More sharing options...
btherl Posted May 2, 2007 Share Posted May 2, 2007 Can you show us the output of "echo $sql;" just after you set $sql for your delete statement? Quote Link to comment https://forums.phpfreaks.com/topic/49619-solved-error-in-code-can-anyone-be-my-hero-and-spot-it/#findComment-243276 Share on other sites More sharing options...
btherl Posted May 2, 2007 Share Posted May 2, 2007 Oh, I didn't look properly. You should use mysql_query($sql), not mysql_query($query) Quote Link to comment https://forums.phpfreaks.com/topic/49619-solved-error-in-code-can-anyone-be-my-hero-and-spot-it/#findComment-243277 Share on other sites More sharing options...
jeaker Posted May 2, 2007 Author Share Posted May 2, 2007 WOW, Thanks btherl for the fresh set of eyes. Been looking at code way too long today. Quote Link to comment https://forums.phpfreaks.com/topic/49619-solved-error-in-code-can-anyone-be-my-hero-and-spot-it/#findComment-243280 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.