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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.