twilitegxa Posted July 8, 2009 Share Posted July 8, 2009 Now when I try to delete a record from my database, it produces the following error: Notice: Undefined variable: display_block in C:\wamp\www\delentry.php on line 82 Here is my code: <?php //connect to database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); if(!isset($_POST['op'])) { //havent seen the form, so show it $display_block = "<h1>Select An Entry</h1>"; //get parts of records $get_list = "select id, concat_ws(', ', l_name, f_name) as display_name from master_name order by l_name, f_name"; $get_list_res = mysql_query($get_list) or die(mysql_error()); if (mysql_num_rows($get_list_res) < 1) { //no records $display_block .= "<p><em>Sorry, no records to select!</em></p> <p align=\"center\"><a href=\"mymenu.php\">Back To Main Page</a></p>"; } else { //has records, so get results 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 = mysql_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> <input type=\"hidden\" name=\"op\" value=\"delete\"> <p><input type=\"submit\" name=\"submit\" value=\"Delete Selected Entry\"></p> </form>"; } } else if(!isset($_POST['op'])) { //check for required fields if ($_POST['sel_id'] == "") { header("Location: delentry.php"); exit; } //issue queries $del_master = "delete from master_name where id = $_POST[sel_id]"; mysql_query($del_master); $del_adress = "delete from address where id = $_POST[sel_id]"; mysql_query($del_address); $del_tel = "delete from telephone where id = $_POST[sel_id]"; mysql_query($del_tel); $del_fax = "delete from fax where id = $_POST[sel_id]"; mysql_query($del_fax); $del_email = "delete from email where id = $_POST[sel_id]"; mysql_query($del_email); $del_note = "delete from personal_notes where id = $_POST[sel_id]"; mysql_query($del_note); $display_block = "<h1>Record(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 print $display_block; ?> </body> </html> How is this variable not defined? What have I done wrong? Line 82 is the <?php print $display_block; ?> at the end. Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted July 8, 2009 Share Posted July 8, 2009 Both of your "if" statments are basically the same thing ... if(!isset($_POST['op']) else if(!isset($_POST['op']) Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 8, 2009 Author Share Posted July 8, 2009 The original code was supposed to be: } else if ($_POST[op] == "view) { and if ($_POST[op] != "view") { but I was getting another error and was told to change the first one to: if(!isset($_POST['op']) so I assumed I would make the same changes to the other one. Can anyone tell me what I am supposed to change these to? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 12, 2009 Author Share Posted July 12, 2009 I changed the print to echo int he display_block message and changes the else if statement to } else if(isset($_POST['op'])) { instead of } else if(!isset($_POST['op'])) {. But now some of the records are deleting and some are not. The emails, personal notes, and telephone numbers deleted from their respective tables, but the address and fax numbers did not delete. There were also some undefined variable errors, but I can't remember which ones now. But now it says there are no records in the database. It said the records were deleted and like I said, some of the field were deleted, but some weren't. Can anyone help with the reason why maybe the fax and address fields were not deleted? Quote Link to comment 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.