zumorikato Posted April 9, 2010 Share Posted April 9, 2010 Hi Guys Im running PHP V5, and using n Mysql DB, o and its running on apache. Im very new to php but are unfortunatly forced by my employer to deliver a product developed in it. I would really like to ask for you guys to assist me with a specific problem that Im currently experiencing. I currently have a web page that contains a table. This table is being populated/created from a mysql DB. It contains 4 columns. The first is a Unique ID (very important, as this is the value I want). The second is the Description, the third is a tick box. The forth is not relevant. At the bottom of the page I have a delete button. I want to give the user the ability to select multiple tick boxes and press the Delete button, This needs to get the Unique ID (1st columns) value and then be submitted via a SQL query to the DB and then delete it from the DB. How ever I have no Idea how to get the values that are select and fomulate the Query dependent on the amount of items. Can someone please assist me. I have posted the code that Im currently using to create/populate the table. Thanx for any help in advance I really appreciate it. <?php $sql = "SELECT customer_id, customer_description FROM customer order by customer_id desc"; $result = mysql_query($sql); $counter = 0; while ($row=mysql_fetch_row($result)) { if ($counter % 2) { $BColour = "FAFAFA"; } else { $BColour = "EFEFEF"; } $counter = $counter + 1; echo "<tr bgcolor='#$BColour'>"; echo "<td>"; echo $row[0]; echo "</td>"; echo "<td>"; echo $row[1]; echo "</td>"; echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='check" . $row[5] . "' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>"; echo "<td>"; echo '<a href="/company/index.php/heading=Customer&action=Edit&customer_id=' . $row[0] . '" style="text-decoration:none;"><span>Edit</span></a> '; echo "</td>"; echo "</tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198087-struggle-to-retrieve-information-from-tick-boxes/ Share on other sites More sharing options...
cs.punk Posted April 9, 2010 Share Posted April 9, 2010 Try this First put your table in a form Change echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='check" . $row[5] . "' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>"; to echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='entry' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>"; and add <input type='submit' value='Delete' /> on the end On php's side <?php if (isset($_POST['delete'])) {is_array($_POST['entry'])) {foreach ($_POST['entry'] as $id) {$sql = "DELETE FROM customer_order WHERE id='$id'"; $query = mysql_query($sql); } } } ?> .. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/198087-struggle-to-retrieve-information-from-tick-boxes/#findComment-1039357 Share on other sites More sharing options...
zumorikato Posted April 9, 2010 Author Share Posted April 9, 2010 Thanx for the help thus far Im starting to see how it fits in the big picture LOL : 0 I have a syntax problem though. I get Parse error: syntax error, unexpected '{' at the following place {foreach ($_POST['entry'] as $id) I know it sounds stupid but I have tried to fiddle with it a little but cant seem to solve the problem? It looks right in my eyes, but maybe Im going blind? Can you perhaps tell me why its moaning about the { ? Quote Link to comment https://forums.phpfreaks.com/topic/198087-struggle-to-retrieve-information-from-tick-boxes/#findComment-1039373 Share on other sites More sharing options...
jcbones Posted April 9, 2010 Share Posted April 9, 2010 This line should be: echo "<td class='style1' align='center' valign='middle'><input type='checkbox' name='entry[]' value='" . $row[5] . "' id='check" . $row[5] . "'/></td>"; And the PHP should be. <?php if (isset($_POST['delete'])){ if(is_array($_POST['entry'])) { foreach ($_POST['entry'] as $id) { $sql = "DELETE FROM customer_order WHERE id='$id'"; $query = mysql_query($sql); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198087-struggle-to-retrieve-information-from-tick-boxes/#findComment-1039453 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.