knnakai Posted July 16, 2009 Share Posted July 16, 2009 I don't really know what is wrong with the code it shows this error message? Could anybody help? (You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '3'' at line 1) the code is: <?php $mysqli = mysqli_connect("localhost", "root", "root", "test"); if (!$_POST) { //Show the selected form $display_block = "<h1>Select an Entry</h1>"; //get parts of recordes $get_list_sql ="SELECT id, CONCAT_WS(', ', l_name, f_name) AS display_name FROM master_name ORDER BY l_name, f_name"; $get_list_res =mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_list_res) < 1) { //No records $display_block .= "<p><em>Sorry, no recordes to select!</em></p>"; } else { //Has result, get result and print in a form $display_block .= " <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\"> <p><strong>Select a Record to Delete:</strong><br/> <select name=\"sel_id\"> <option value=\"\">-- Select One --</option>"; while ($recs = mysqli_fetch_array($get_list_res)) { $id = $recs['id']; $display_name = stripslashes($recs["display_name"]); $display_block .= "<option value=\"".$id."\">". $display_name."</option>"; } $display_block .= " </select> <p><input type=\"submit\" name=\"submit\" value=\"Delete Selected Entry\"></p> </form>"; } // free result mysqli_free_result($get_list_res); } else if ($_POST) { //check for required field if ($_POST["sel_id"] == "") { header("Location: delentry.php"); exit; } //issue queries $del_master_sql = "DELETE FROM master_name, WHERE id = '".$_POST["sel_id"]."'"; $del_master_res = mysqli_query($mysqli, $del_master_sql) or die (mysqli_error($mysqli)); $del_address_sql = "DELETE FROM address WHERE id = '".$_POST["sel_id"]."'"; $del_address_res = mysqli_query($mysqli, $del_address_sql) or die(mysqli_error($myslqi)); $del_tel_sql = "DELETE FROM telephone WHERE id ='".$_POST["sel_id"]."'"; $del_tel_res = mysqli_query($mysqli, $del_tel_sql) or die(mysqli_error($mysqli)); $del_fax_sql = "DELETE FROM fax WHERE id = '".$_POST["sel_id"]."'"; $del_fax_res = mysqli_query($mysqli, $del_fax_sql) or die(mysqli_error($mysqli)); $del_email_sql = "DELETE FROM email WHERE id = '".$_POST["sel_id"]."'"; $del_email_res = mysqli_query($mysqli, $del_email_sql) or die(mysqli_error($mysqli)); $del_note_sql = "DELETE FROM personal_notes WHERE id = '".$_POST["sel_id"]."'"; $del_note_res = mysqli_query($mysqli, $del_note_sql) or die(mysqli_error($mysqli)); $display_block = "<h1>Recod (s) Deleted</h1> <p>Would you like to <a href=\"".$_SERVER["PHP_SELF"]."\">Delete another</a>?</p>"; } ?> <html> <head> <title>My Records</title> </head> <body> <?php echo $display_block; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/166204-solved-php-code-error/ Share on other sites More sharing options...
ignace Posted July 16, 2009 Share Posted July 16, 2009 DELETE FROM master_name, WHERE should be: DELETE FROM master_name WHERE Link to comment https://forums.phpfreaks.com/topic/166204-solved-php-code-error/#findComment-876419 Share on other sites More sharing options...
knnakai Posted July 16, 2009 Author Share Posted July 16, 2009 Cool it works fine. Thanx a lot. Link to comment https://forums.phpfreaks.com/topic/166204-solved-php-code-error/#findComment-876495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.