Hi,
I have a simple script that connects to my MySQL database, and shows me the data that I have requested in a table layout.
I have searched a few guides and I am struggling with the next bit though, I want to display a checkbox at the end of each row and select and then a button to delete. Any ideas on how I can do this?
here is my code so far that calls the information
PHP Code:
<?
mysql_connect("","","") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
foreach($_POST['rm[]'] as $key => $val){// check all results
if(!is_int($val))// if the result is not a number
unset($_POST['rm'][$key]);// remove it from listings.
};
// run remove:
mysql_query("DELETE FROM tbl WHERE ID IN (".implode($_POST['rm[]'], ', ').")");
If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.
Hi Thanks for your help, I think I am nearly there, so I have set up the ID in MySQL and added the checkboxes, the form action I have set as delete.php and then created this file as;
PHP Code:
<?
foreach($_POST['rm[]'] as $key => $val){// check all results
if(!is_int($val))// if the result is not a number
unset($_POST['rm'][$key]);// remove it from listings.
};
// run remove:
mysql_query("DELETE FROM tbl WHERE ID IN (".implode($_POST['rm[]'], ', ').")"); ?>
however I get these errors
Warning: Invalid argument supplied for foreach() in /home/ayoocouk/public_html/mywebsite.co.uk/delete.php on line 7
Warning: implode() [function.implode]: Bad arguments. in /home/ayoocouk/public_html/mywebsite.co.uk/delete.php on line 12
<?
if(isset($_POST['rm[]'])){
foreach($_POST['rm[]'] as $key => $val){// check all results
if(!is_int($val))// if the result is not a number
unset($_POST['rm'][$key]);// remove it from listings.
};
// run remove:
if(count($_POST['rm[]'])){
mysql_query("DELETE FROM tbl WHERE ID IN (".implode($_POST['rm[]'], ', ').")");
echo mysql_affect_rows()." results deleted.";
};
};
?>
forgot checking, sorry.
and replace tbl in the query with your table name.
If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.
<?
if(isset($_POST['rm'])){
foreach($_POST['rm'] as $key => $val){// check all results
if(!is_int($val))// if the result is not a number
unset($_POST['rm'][$key]);// remove it from listings.
};
// run remove:
if(count($_POST['rm'])){
mysql_query("DELETE FROM tbl WHERE ID IN (".implode($_POST['rm'], ', ').")");
echo mysql_affect_rows()." results deleted.";
};
};
?>
after a bit of testing it works out that PHP5(and possibly PHP4) submits as an array without the [] in it's name, use the version above if you have any problems.
If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.
Bookmarks