Esqulax Posted November 30, 2007 Share Posted November 30, 2007 Hiya, if anyone can help, id be really appreciative... Basically, im trying to get info from the checkboxes on delete.php, pass it to del.php and run a delete script. It wasnt working, so in del.php i put in a count() to see if any info is actually being passed into it.. i get a big fat 0 This is so vexing, its been annoying me for days Code: delete.php: <html> <head> <title>DELETED!</title> </head> <?php //Standard connection scripts $conn=@mysql_connect("localhost","root","") or die("error connecting to database"); $rs=@mysql_select_db("hotel", $conn) or die("Error connecting to Hotel"); $sql = "SELECT * FROM guest_data ORDER BY guest_id, name, surname"; $result = mysql_query($sql,$conn) or die("error using result query"); echo ("<table border= 1>"); echo ('<form method="post" action="'.$self.'">'); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr>\n"; echo "<td>". $row['guest_id'] . '<input name="guestid[]" type="checkbox" value="' . $row['guest_id'] . '"></td>'; echo "<td>" . $row['name'] ; echo "<td>" . $row['surname']; } ?> <tr> <td> <input type="submit" name="submit" value="submit"></td> </form> </tr> </table> <?php echo('<form method="post" action="del.php">'); $delid = $_POST["guestid"]; $how_many=count($delid); if ($how_many>0) { echo ("You chose the following records:<br>"); for ($i=0; $i<$how_many; $i++) { echo (($i+1) . " - " . $delid[$i] . "<br>"); } echo("Ok to delete ".$how_many." record(s)?"); echo('<input type="submit" name="submit" value="Yes">'); echo('</form>'); } ?> del.php: <html> <head> <title>Sucessfully Deleted</title> </head> <?php $delvalue=$_POST['guestid']; //Stanatrd connection scripts $conn=@mysql_connect("localhost","root","") or die("error connecting to database"); $rs=@mysql_select_db("hotel", $conn) or die("Error connecting to Hotel"); $amount=count($delvalue); echo(''.$amount); for($i=0;$i<$amount; $i++) { echo(''.$delvalue[$i]); } /* while ($row = mysql_fetch_array($delval)) { $sql2="DELETE FROM guest_data WHERE guest_id=".$delval; $gone= mysql_query($sql2,$conn); } */ ?><!-- <script language="javascript"><!-- location.replace(delete.php") //--> </script>--> <a href="delete.php">Return</a> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/ Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 thats because your 2nd form doesn't have $guestid Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402905 Share on other sites More sharing options...
Esqulax Posted November 30, 2007 Author Share Posted November 30, 2007 My bad... That was a frustrated experiment, the same issue appears if i have (in del.php): $delvalue=$_POST['guestid']; Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402916 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 still doesn't help if you don't put it in the form.. for example for ($i=0; $i<$how_many; $i++) { echo (($i+1) . " - " . $delid[$i] . "<br>"); echo "<input type=\"hidden\" name=\"guestid[]\" value=\"{$delid[$i]}\"> "; //<--add } Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402932 Share on other sites More sharing options...
Esqulax Posted November 30, 2007 Author Share Posted November 30, 2007 Fantastic! So the form diddn't have any info to store, i see. one last syntax Q Is it ok to put the variable on the end of a SELECT or DELETE statement like this? $sql= "SELECT * FROM guest_data WHERE guest_id=".$delvalue; $result = mysql_query($sql,$conn) or die("error using result query"); while ($row = mysql_fetch_array($result)) { $sql2="DELETE FROM guest_data WHERE guest_id=".$delvalue; $gone= mysql_query($sql2,$conn); } [/code Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402940 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 yes that fine.. Techie Tip: you have an array of ID's ie $_POST['guestid']; array(1,2,3,6,8,10) etc you can do this <?php $delvalue=implode(",",$_POST['guestid']); //returns "1,2,3,6,8,10" $sql2="DELETE FROM guest_data WHERE guest_id IN ($delvalue)"; //SQL statment to deletes all the records in one hit ?> Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402959 Share on other sites More sharing options...
Esqulax Posted November 30, 2007 Author Share Posted November 30, 2007 Sorted! Massive weight is herby lifted!! Thanks Loads! Link to comment https://forums.phpfreaks.com/topic/79555-solved-passing-info-from-forms-for-deletion/#findComment-402977 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.