Pikachu2000 Posted June 18, 2010 Share Posted June 18, 2010 What do you mean it removes all the info? Do you mean it deletes all records from the database, or it displays a blank screen? Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074197 Share on other sites More sharing options...
dsjoes Posted June 18, 2010 Author Share Posted June 18, 2010 it displays the below with check boxes at the end of the line and the delete and cancel button at the bottom. When i click a check box and delete it removes the info below until i change page and come back. then it is there again Target: Test Comment: Test 1 Select to delete: Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074200 Share on other sites More sharing options...
jcbones Posted June 18, 2010 Share Posted June 18, 2010 This: for($i=0;$i<count($_POST['checkbox']);$i++){ Â Â Â Â Â Â Â Â Â Â Â Â if($i != 0) $sql.= "AND "; Â Â Â Â Â Â Â Â Â Â Â Â $sql .= " ID='" . $_POST['checkbox'][$i] . "'"; Â Â Â Â Â Â Â Â } Â Should be: for($i=0;$i<count($_POST['checkbox']);$i++){ Â Â Â Â Â Â Â Â Â Â Â Â if($i != 0) $sql.= "OR "; Â Â Â Â Â Â Â Â Â Â Â Â $sql .= " ID='" . $_POST['checkbox'][$i] . "'"; Â Â Â Â Â Â Â Â } Â I don't think many rows would have an id of 1 and 2 and 3 and 4 and 5. Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074201 Share on other sites More sharing options...
Pikachu2000 Posted June 18, 2010 Share Posted June 18, 2010 it displays the below with check boxes at the end of the line and the delete and cancel button at the bottom. When i click a check box and delete it removes the info below until i change page and come back. then it is there again Target: Test Comment: Test 1 Select to delete: Â OK, but have you checked that database to see if the records are still there? If you're using the 'Back' button, of course it will redisplay the info. Right now, I'm just trying to get you to a point that the script actually deletes the selected record from the database. Once we accomplish that, then we can move on to presenting a success/failure message, and redirecting to an appropriate page thereafter. Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074205 Share on other sites More sharing options...
dsjoes Posted June 18, 2010 Author Share Posted June 18, 2010 jcbones that is doing the same thing  Pikachu2000 yes the info is still there i didn't use the back button Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074206 Share on other sites More sharing options...
jcbones Posted June 18, 2010 Share Posted June 18, 2010 Comment out this line: if(isset($_POST['delete'])) header('Location: admin.php'); // redirect  Like: // if(isset($_POST['delete'])) header('Location: admin.php'); // redirect Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074208 Share on other sites More sharing options...
dsjoes Posted June 18, 2010 Author Share Posted June 18, 2010 Comment out this line: if(isset($_POST['delete'])) header('Location: admin.php'); // redirect  Like: // if(isset($_POST['delete'])) header('Location: admin.php'); // redirect  still the same it adds new empty rows Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074209 Share on other sites More sharing options...
Pikachu2000 Posted June 18, 2010 Share Posted June 18, 2010 OK. Do a forced refresh of the page, Internet Explorer is CTRL-F5, I believe, or close and reopen the bowser, then view the page source, and cut and paste it here so I can see what is going on. Also, please post the database field names exactly as they are. Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074210 Share on other sites More sharing options...
jcbones Posted June 18, 2010 Share Posted June 18, 2010 Also change: $result = mysql_query($sql); Â To: echo 'Query: ' . $sql; $result = mysql_query($sql); Â Paste the print out. Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074211 Share on other sites More sharing options...
dsjoes Posted June 19, 2010 Author Share Posted June 19, 2010 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- TemplateBeginEditable name="doctitle" --> <title>Admin</title> <!-- TemplateEndEditable --> <!-- TemplateBeginEditable name="head" --> <!-- TemplateEndEditable --> <link href="adminsettings.css" rel="stylesheet" type="text/css" /> </head> Â <body> Â <div class="container"> Â <div class="header"><p>Saturday 19th of June 2010 12:58 AM (BST)</p><center><p><img src="pics/logo.png" alt="Logo" name="Insert_logo" width="540" height="196" id="Insert_logo" style="background: #000000; display:block;" /></p></center> Â Â <!-- end .header --></div> Â <div class="sidebar1"> Â Â <ul class="nav"> Â Â Â <li><a href="index.php"><img title='Generated button' src='Buttons/home.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/home1.png"' onmouseout='javascript:this.src="Buttons/home.png"' /></a></li> Â Â Â <li><a href="claninfo.php"><img title='Generated button' src='Buttons/clan info.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/clan info1.png"' onmouseout='javascript:this.src="Buttons/clan info.png"' /></a></li> Â Â Â <li><a href="faq.php"><img title='Generated button' src='Buttons/faq.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/faq1.png"' onmouseout='javascript:this.src="Buttons/faq.png"' /></a></li> Â Â Â <li><a href="admin.php"><img title='Generated button' src='Buttons/admin.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/admin1.png"' onmouseout='javascript:this.src="Buttons/admin.png"' /></a></li> Â Â Â <li><a href="password_protect.php?logout=1"><img title='Generated button' src='Buttons/logout.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/logout1.png"' onmouseout='javascript:this.src="Buttons/logout.png"' /></a></li> Â Â </ul> Â Â <p>The admin page logs you out automatically after 30 minutes.</p> Â Â <!-- end .sidebar1 --></div> Â <div class="content"> Â Â <center><h1>Admin</h1> Â Â Â Â <p>Enter the targets name and comment here.</p> Â Â <p><form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /></p> Â Â <p>To delete a target click on the check box and then on delete.</p> Â Â <table align="center" width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="delete" method="post" action="/admin.php"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="4" align="center" bgcolor="#000000"><strong>Targets</strong> </td> </tr> <tr> <td align="center" bgcolor="#000000"><strong>Select</strong></td> <td align="center" bgcolor="#000000"><strong>ID</strong></td> <td align="center" bgcolor="#000000"><strong>Target</strong></td> <td align="center" bgcolor="#000000"><strong>Comment</strong></td> </tr> Â Â Â Â <tr> Â Â Â Â Â Â Â Â <td align="center" bgcolor="#000000"> Â Â Â Â Â Â Â Â Â Â Â Â <input name="checkbox[]" type="checkbox" id="checkbox[]" value="1"> Â Â Â Â Â Â Â Â </td> Â Â Â Â Â Â Â Â <td bgcolor="#000000">1</td> Â Â Â Â Â Â Â Â <td bgcolor="#000000">Test</td> Â Â Â Â Â Â Â Â <td bgcolor="#000000">Test 1</td> Â Â Â Â </tr> Â Â Â Â <tr> Â Â Â Â <td colspan="5" align="center" bgcolor="#000000"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> </table> <p> </p> <p> </p> Â Â <!-- end .content --></div> Â <div class="sidebar2"> Â Â <h4>Â </h4> Â Â <!-- end .sidebar2 --></div> Â <div class="footer"> Â Â <p>Â </p> Â Â <!-- end .footer --></div> Â <!-- end .container --></div> </body> </html> Â Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074212 Share on other sites More sharing options...
dsjoes Posted June 19, 2010 Author Share Posted June 19, 2010 Also change: $result = mysql_query($sql); Â To: echo 'Query: ' . $sql; $result = mysql_query($sql); Â Paste the print out. Â Â Still this Query: SELECT * FROM Target ORDER BY ID Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074214 Share on other sites More sharing options...
Pikachu2000 Posted June 19, 2010 Share Posted June 19, 2010 First thing I see is that there nested <form> tags, and neither of them get closed. <form action=insert.php is opened, then shortly after, <form action=admin.php is opened. That may not be causing all of your problems, but I'll bet it isn't helping. When you click the delete button, what page shows in the address bar of the browser? Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074220 Share on other sites More sharing options...
dsjoes Posted June 19, 2010 Author Share Posted June 19, 2010 the admin.php page Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074223 Share on other sites More sharing options...
jcbones Posted June 19, 2010 Share Posted June 19, 2010 I just tested on my test server. Using a double form with no closing tag, will send the data to the first form action.  In this case "Insert.php".  Good eye Pik.  Edit: I'm betting you see the admin.php because you have a redirect in "insert.php". Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074252 Share on other sites More sharing options...
Pikachu2000 Posted June 19, 2010 Share Posted June 19, 2010 I think a lot of the problem here is that we don't have all of the code. This script is include()d in another script, and we can't tell what really needs to be done. WIthout being able to see ALL of the code that is being executed, it's nothing but a craps shoot. Please post the all of the relevant code so we can actually be of some help to you. Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074257 Share on other sites More sharing options...
dsjoes Posted June 19, 2010 Author Share Posted June 19, 2010 that is all of the script the only script i have not list is the insert.php which has nothing to do with the delete script it is for adding to the database and the css style page.  insert.php <?php $con = mysql_connect("host","user","pass"); if (!$con)  {  die('Could not connect: ' . mysql_error());  } mysql_select_db("KAW", $con); $sql="INSERT INTO Target(Target, Comment) VALUES ('$_POST[Target]','$_POST[Comment]')"; if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  } echo "Record added"; header('Location: admin.php'); mysql_close($con) ?>  and the css @charset "utf-8"; body { font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif; background: #000000; margin: 0; padding: 0; color: #fff; } /* ~~ Element/tag selectors ~~ */ ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */ padding: 0; margin: 0; } h1, h2, h3, h4, h5, h6, p { margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */ padding-right: 15px; padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */ } a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */ border: none; } /* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */ a:link { color: #42413C; text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */ } a:visited { color: #6E6C64; text-decoration: underline; } a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */ text-decoration: underline; } /* ~~ This fixed width container surrounds all other divs ~~ */ .container { width: 960px; background: #000000; margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout */ } /* ~~ The header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo. ~~ */ .header { background: #000000; } /* ~~ These are the columns for the layout. ~~ 1) Padding is only placed on the top and/or bottom of the divs. The elements within these divs have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design. 2) No margin has been given to the columns since they are all floated. If you must add margin, avoid placing it on the side you're floating toward (for example: a right margin on a div set to float right). Many times, padding can be used instead. For divs where this rule must be broken, you should add a "display:inline" declaration to the div's rule to tame a bug where some versions of Internet Explorer double the margin. 3) Since classes can be used multiple times in a document (and an element can also have multiple classes applied), the columns have been assigned class names instead of IDs. For example, two sidebar divs could be stacked if necessary. These can very easily be changed to IDs if that's your preference, as long as you'll only be using them once per document. 4) If you prefer your nav on the right instead of the left, simply float these columns the opposite direction (all right instead of all left) and they'll render in reverse order. There's no need to move the divs around in the HTML source. */ .sidebar1 { float: left; width: 180px; background: #000000; padding-bottom: 10px; } .content { padding: 10px 0; width: 600px; float: left; } .sidebar2 { float: left; width: 180px; background: #000000; padding: 10px 0; } /* ~~ This grouped selector gives the lists in the .content area space ~~ */ .content ul, .content ol { padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */ } /* ~~ The navigation list styles (can be removed if you choose to use a premade flyout menu like Spry) ~~ */ ul.nav { list-style: none; /* this removes the list marker */ border-top: none; /* this creates the top border for the links - all others are placed using a bottom border on the LI */ margin-bottom: 15px; /* this creates the space between the navigation on the content below */ } ul.nav li { border-bottom: none; /* this creates the button separation */ } ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */ padding: 5px 5px 5px 15px; display: block; /* this gives the anchor block properties so it fills out the whole LI that contains it so that the entire area reacts to a mouse click. */ width: 100px; /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */ text-decoration: none; background: #000000; } ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */ background: #000000; color: #FFF; } /* ~~ The footer styles ~~ */ .footer { padding: 10px 0; background: #000000; position: relative;/* this gives IE6 hasLayout to properly clear */ clear: both; /* this clear property forces the .container to understand where the columns end and contain them */ } /* ~~ Miscellaneous float/clear classes ~~ */ .fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */ float: right; margin-left: 8px; } .fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */ float: left; margin-right: 8px; } .clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the .container) if the .footer is removed or taken out of the .container */ clear:both; height:0; font-size: 1px; line-height: 0px; }  and like i said in the first post i could delete from the database fine before i changed the website so that it would display correctly in IE using the css file and template from dreamweaver because i had never used a css style sheet before Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1074326 Share on other sites More sharing options...
dsjoes Posted June 21, 2010 Author Share Posted June 21, 2010 anyone Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1075224 Share on other sites More sharing options...
dsjoes Posted June 22, 2010 Author Share Posted June 22, 2010 i have created the the page again from scratch with a new database and i have added a bit and tested it as i went along and i think i have found the problem.  this is the test page called test.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link href="adminsettings.css" rel="stylesheet" type="text/css" /> </head> <body>  <div class="header"><p><?php date_default_timezone_set('Europe/London'); $today = date("l dS \of F Y h:i A (T)"); echo $today; ?></p><center><p><img src="pics/logo.png" alt="Logo" name="Insert_logo" width="540" height="196" id="Insert_logo" style="background: #000000; display:block;" /></p></center></div>  <div class="sidebar1">   <ul class="nav">    <li><a href="index.php"><img title='Generated button' src='Buttons/home.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/home1.png"' onmouseout='javascript:this.src="Buttons/home.png"' /></a></li>    <li><a href="claninfo.php"><img title='Generated button' src='Buttons/clan info.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/clan info1.png"' onmouseout='javascript:this.src="Buttons/clan info.png"' /></a></li>    <li><a href="faq.php"><img title='Generated button' src='Buttons/faq.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/faq1.png"' onmouseout='javascript:this.src="Buttons/faq.png"' /></a></li>    <li><a href="admin.php"><img title='Generated button' src='Buttons/admin.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/admin1.png"' onmouseout='javascript:this.src="Buttons/admin.png"' /></a></li>    <li><a href="password_protect.php?logout=1"><img title='Generated button' src='Buttons/logout.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/logout1.png"' onmouseout='javascript:this.src="Buttons/logout.png"' /></a></li>   </ul>   <p>The admin page logs you out automatically after 30 minutes.</p> </div> <div class="content"> <center><h1>Admin</h1>     <p>Enter the targets name and comment here.</p>   <p><form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /></p>   <p>To delete a target click on the check box and then on delete.</p> <p><?php $host="host"; // Host name $username="user"; // Mysql username $password="pass"; // Mysql password $db_name="Test"; // Database name $tbl_name="Targets"; // Table name        // Connect to server and select databse.     mysql_connect("$host", "$username", "$password")or die("cannot connect");     mysql_select_db("$db_name")or die("cannot select DB");        // Build SQL query     if(!isset($_POST['delete'])) $sql="SELECT * FROM $tbl_name ORDER BY ID";     else {         $sql = "DELETE FROM $tbl_name WHERE";         // add row id to where section         for($i=0;$i<count($_POST['checkbox']);$i++){             if($i != 0) $sql.= "AND ";             $sql .= " ID='" . $_POST['checkbox'][$i] . "'";         }   }    $result = mysql_query($sql);    if(isset($_POST['delete'])) header('Location: test.php'); // redirect ?> <table align="center" width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="4" align="center" bgcolor="#000000"><strong>Targets</strong> </td> </tr> <tr> <td align="center" bgcolor="#000000"><strong>Select</strong></td> <td align="center" bgcolor="#000000"><strong>ID</strong></td> <td align="center" bgcolor="#000000"><strong>Target</strong></td> <td align="center" bgcolor="#000000"><strong>Comment</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?>     <tr>         <td align="center" bgcolor="#000000">             <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['ID']; ?>">         </td>         <td bgcolor="#000000"><? echo $rows['ID']; ?></td>         <td bgcolor="#000000"><? echo $rows['Target']; ?></td>         <td bgcolor="#000000"><? echo $rows['Comment']; ?></td>     </tr>     <tr>     <td colspan="5" align="center" bgcolor="#000000"><input name="delete" type="submit" id="delete" value="Delete"></td>     </tr> <?php }     mysql_close(); ?> </table> </form> </td> </tr> </table></p> </center></div> </body> </html>  the above dosen't work unless i remove the part below <p><form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /></p>  when i delete a row the page should stay on test.php but with the bit above in it goes to the admin.php page so it does not delete anything. The part above is to add to the database.  this is the insert.php script <?php $con = mysql_connect("host","user","pass"); if (!$con)  {  die('Could not connect: ' . mysql_error());  } mysql_select_db("KAW", $con); $sql="INSERT INTO Target(Target, Comment) VALUES ('$_POST[Target]','$_POST[Comment]')"; if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  } echo "Record added"; header('Location: admin.php'); mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1075844 Share on other sites More sharing options...
dsjoes Posted June 24, 2010 Author Share Posted June 24, 2010 anyone know how to fix the above Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1076710 Share on other sites More sharing options...
dsjoes Posted June 26, 2010 Author Share Posted June 26, 2010 i have created the the page again from scratch with a new database and i have added a bit and tested it as i went along and i think i have found the problem.  this is the test page called test.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link href="adminsettings.css" rel="stylesheet" type="text/css" /> </head> <body>  <div class="header"><p><?php date_default_timezone_set('Europe/London'); $today = date("l dS \of F Y h:i A (T)"); echo $today; ?></p><center><p><img src="pics/logo.png" alt="Logo" name="Insert_logo" width="540" height="196" id="Insert_logo" style="background: #000000; display:block;" /></p></center></div>  <div class="sidebar1">   <ul class="nav">    <li><a href="index.php"><img title='Generated button' src='Buttons/home.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/home1.png"' onmouseout='javascript:this.src="Buttons/home.png"' /></a></li>    <li><a href="claninfo.php"><img title='Generated button' src='Buttons/clan info.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/clan info1.png"' onmouseout='javascript:this.src="Buttons/clan info.png"' /></a></li>    <li><a href="faq.php"><img title='Generated button' src='Buttons/faq.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/faq1.png"' onmouseout='javascript:this.src="Buttons/faq.png"' /></a></li>    <li><a href="admin.php"><img title='Generated button' src='Buttons/admin.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/admin1.png"' onmouseout='javascript:this.src="Buttons/admin.png"' /></a></li>    <li><a href="password_protect.php?logout=1"><img title='Generated button' src='Buttons/logout.png' style="border-style: none" onmouseover='javascript:this.src="Buttons/logout1.png"' onmouseout='javascript:this.src="Buttons/logout.png"' /></a></li>   </ul>   <p>The admin page logs you out automatically after 30 minutes.</p> </div> <div class="content"> <center><h1>Admin</h1>     <p>Enter the targets name and comment here.</p>   <p><form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /></p>   <p>To delete a target click on the check box and then on delete.</p> <p><?php $host="host"; // Host name $username="user"; // Mysql username $password="pass"; // Mysql password $db_name="Test"; // Database name $tbl_name="Targets"; // Table name        // Connect to server and select databse.     mysql_connect("$host", "$username", "$password")or die("cannot connect");     mysql_select_db("$db_name")or die("cannot select DB");        // Build SQL query     if(!isset($_POST['delete'])) $sql="SELECT * FROM $tbl_name ORDER BY ID";     else {         $sql = "DELETE FROM $tbl_name WHERE";         // add row id to where section         for($i=0;$i<count($_POST['checkbox']);$i++){             if($i != 0) $sql.= "AND ";             $sql .= " ID='" . $_POST['checkbox'][$i] . "'";         }   }    $result = mysql_query($sql);    if(isset($_POST['delete'])) header('Location: test.php'); // redirect ?> <table align="center" width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td colspan="4" align="center" bgcolor="#000000"><strong>Targets</strong> </td> </tr> <tr> <td align="center" bgcolor="#000000"><strong>Select</strong></td> <td align="center" bgcolor="#000000"><strong>ID</strong></td> <td align="center" bgcolor="#000000"><strong>Target</strong></td> <td align="center" bgcolor="#000000"><strong>Comment</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?>     <tr>         <td align="center" bgcolor="#000000">             <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['ID']; ?>">         </td>         <td bgcolor="#000000"><? echo $rows['ID']; ?></td>         <td bgcolor="#000000"><? echo $rows['Target']; ?></td>         <td bgcolor="#000000"><? echo $rows['Comment']; ?></td>     </tr>     <tr>     <td colspan="5" align="center" bgcolor="#000000"><input name="delete" type="submit" id="delete" value="Delete"></td>     </tr> <?php }     mysql_close(); ?> </table> </form> </td> </tr> </table></p> </center></div> </body> </html>  the above dosen't work unless i remove the part below <p><form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /></p>  when i delete a row the page should stay on test.php but with the bit above in it goes to the admin.php page so it does not delete anything. The part above is to add to the database.  this is the insert.php script <?php $con = mysql_connect("host","user","pass"); if (!$con)  {  die('Could not connect: ' . mysql_error());  } mysql_select_db("KAW", $con); $sql="INSERT INTO Target(Target, Comment) VALUES ('$_POST[Target]','$_POST[Comment]')"; if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  } echo "Record added"; header('Location: admin.php'); mysql_close($con) ?>  Anyone Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1077678 Share on other sites More sharing options...
jcbones Posted June 26, 2010 Share Posted June 26, 2010 You see this form? <form action="insert.php" method="post"> Â CLOSE IT. <form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1077721 Share on other sites More sharing options...
dsjoes Posted June 27, 2010 Author Share Posted June 27, 2010 You see this form? <form action="insert.php" method="post"> Â CLOSE IT. <form action="insert.php" method="post"> Target: <input type="text" name="Target" /> Comment: <input type="text" name="Comment" /> <input type="submit" /> </form> Â Thanks i carn't believe i didn't see that. Â do you know how i could do it so that i can update a row with out deleting it or to replace the row with the new info if the target is the same. Â Thanks Quote Link to comment https://forums.phpfreaks.com/topic/203991-help-with-deleting-from-sql-database/page/2/#findComment-1077813 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.