Jump to content

Newbie - so close! can't get select check box to delete record to work...


greencoin

Recommended Posts

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;
} 
?>

Link to comment
Share on other sites

 

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. {}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.