Jump to content

[SOLVED] Error in Code? Can anyone be my Hero and Spot it?


jeaker

Recommended Posts

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!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.