greencoin Posted June 13, 2007 Share Posted June 13, 2007 Hi again - ugh I feel like an idiot having to ask for so much help. This last bit of code should finish my project up but I'm having a hard time getting it working. It's supposed to post the variables to itself and refresh the page when the record is deleted but I can't get the records to delete. I was getting the page to refresh however - just no deleted records?! (it's currently kicking out "T_ENCAPSED_AND_WHITESPACE" errors on line 34 cause I made a change on my submit button - that's not the real problem however) Take a look at it please and tell me what I'm doing wrong. Thanks in advance, AGAIN.. ??? ~Rich <?php $con = mysql_connect("xxxxxxxxxxx", "GCsales", "xxxxxxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } $view=$_GET["view"]; $id=$_GET["cid"]; switch ($view) { case "list": mysql_select_db("GCsales", $con); $result = mysql_query("SELECT * FROM GC_Tracker"); echo "<table border='1'> <tr> <td>Name</td> <td>Sex</td> <td>Age</td> <td>Delete</td> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['customer'] . "</td>"; echo "<td>" . $row['area'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "<td><input type=\"checkbox\" name=\"delete_items[]\" value=\"" . $row['cid'] . "\"></td>"; echo "</tr>"; } echo "<table border='1'> <tr> <td colspan=4><input type=\"button\" onClick=\"parent.location='delete.php?id=$row['cid']'\"></td>; //<-- this is line 34 </tr>"; echo "</table>"; break; case "delete": $delete_items = implode(",",$_GET['delete_items']); mysql_select_db("WB", $con); mysql_query("DELETE FROM GC_Tracker WHERE cid IN ($delete_items)"); mysql_close($con); $url="delete.php?view=list"; header("Location: $url"); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/ Share on other sites More sharing options...
Wildbug Posted June 13, 2007 Share Posted June 13, 2007 Are you checking for mysql_errno/mysql_error? ...lete.php?id=$row['id']'\"></td>; Is that Line 34? (You should mark which line the error is on with a comment (// This is line 34) or something to make it easier for us.) When interpolating array values into a double quoted string, lose the single quotes around the index. <td colspan=4><input type=\"button\" onClick=\"parent.location='delete.php?id=$row[id]'\"></td> Or you can use curly braces around the variable. {} Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274138 Share on other sites More sharing options...
greencoin Posted June 13, 2007 Author Share Posted June 13, 2007 egads! - the syntax will be the death of me. Have modified the code I posted as requested Tested your input and now I get a blank screen when the delete button is pressed. My url looks like this "http://www.xxxxxxxxx/rich/backend/delete.php?id=" I'm thinkin it should look like "http://www.xxxxxxxxx/rich/backend/delete.php?delete=1" the records I selected are not deleted. Thanx ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274156 Share on other sites More sharing options...
greencoin Posted June 14, 2007 Author Share Posted June 14, 2007 ~Bump~ ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274261 Share on other sites More sharing options...
kalivos Posted June 14, 2007 Share Posted June 14, 2007 If I'm reading this correctly... the checkbox name should be cid. Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274267 Share on other sites More sharing options...
greencoin Posted June 14, 2007 Author Share Posted June 14, 2007 CID is the name of the primary key used in the GC_Tracker table - What the code is supposed to do is query and post table data when loaded using the url "delete.php?view=list". When a checkbox is selected and the delete button is pressed it posts the value of the checkbox(es) in the header and passes those query strings to itself via "delete.php?delete_items=1&delete_items=4...etc" after it gets the query string, it deletes the record from the table and requeries the table for the current info. It was a snippet of code I found and added to but can't seem to get it to work right.... can't figure it out and I know it's gonna be something simple like always. is really kickin my chickin right now. ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274523 Share on other sites More sharing options...
Wildbug Posted June 14, 2007 Share Posted June 14, 2007 If you're trying to create an array of items, your GET URL should be: delete.php?delete_items[]=1&delete_items[]=4...etc - or - delete.php?delete_items%91%93=1&delete_items%91%93=4...etc When debugging it helps to print out the strings you're creating to make sure they make sense. In this case, you should be checking the value of $delete_items. Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274601 Share on other sites More sharing options...
sasa Posted June 14, 2007 Share Posted June 14, 2007 try <td colspan=4><input type=\"button\" onClick=\"parent.location='delete.php?view=delete'\"></td> Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274667 Share on other sites More sharing options...
greencoin Posted June 14, 2007 Author Share Posted June 14, 2007 sorry sasa - this is what I get; "Warning: implode(): Bad arguments. in /home/content/xxxxxxxxxxxxxxxxxxx/delete.php on line 41 Warning: Cannot modify header information - headers already sent by (output started at /home/content/xxxxxxxxxxxx/delete.php:41) in /home/content/xxxxxxxxxxxxxxxxxxxxxxx/delete.php on line 46" thanks ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/55472-newbie-so-close-cant-get-select-check-box-to-delete-record-to-work/#findComment-274927 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.