0

I've created a While loop that prints out the info of a MySQL table into a simple html table. This part works just fine.

I've created a variable which has a prefix tableID and then adds the number of the row ID. ID is the primary key and row is the array.

${'tableID_' . $row['ID']} = $row['ID'];

In the While loop table I've also included form checkboxes, so if it's checked and the submit button is hit, it will delete the row from the table. I've named the checkbox the same as the variable as well as giving it the same value.

<input name=\"${'tableID_' . $row['ID']}\" type=\"checkbox\" value=\"${'tableID_' . $row['ID']}\">"

In the script that processes the delete query, I tried doing this for the variable:

$tabRowDel = $_GET[${'tableID_' . $row['ID']}];

The error is: "Notice: Undefined index: 1 in..." The above is on the line number it tells me the error exists.

I did have it as POST before but decided to try GET to see if it was working at all. It does pass into the URL.

Any ideas on how to get this working? While I'm at it, what's a good way to do a verification? Essentially someone checks the box, hits Submit and a message asks if they really want to delete the info.

Cheers!

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by blocblue
0

I'm not sure that I fully understand why you feel that you need to use dynamic variable names.

Have you tried something like:

<input name="tableId[]" type="checkbox" value="<?php echo $row['ID']" />

This will allow you to select multiple checkboxes, and when submitted, they will all be contained within the variable tableId. You can then access this like:

$tableIds = isset($_POST['tableId')) ? $_POST['tableId') : array();

// Iterate over your table ids to use individually
foreach($tableIds as $tableId)
    echo $tableId;

// Implode table ids into list to use in MySQL in clause.
$tableIds = implode(',', $tableIds);

R.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.