tags:

views:

151

answers:

3
function delete($rowid) 
{
   $rowids = implode(", ",$rowid);
   $sql = "DELETE FROM pms WHERE id IN (".$rowids.")";
   print $sql;
}

if (isset($_POST['submit']))  
{
 delete($rowid);
}

?>

<form method="post" action="test.php">

<input type="checkbox" name="rowid[]" value="1771367" /><br >
<input type="checkbox" name="rowid[]" value="345342" /><br >
<input type="checkbox" name="rowid[]" value="572347" /><br >
<input type="checkbox" name="rowid[]" value="902358" /><br >
<input type="checkbox" name="rowid[]" value="234654" /><br ><br >

<input type="submit" name="submit" />

</form>

Warning: implode() [function.implode]: Invalid arguments passed in C:\pub\test.php on line 4 DELETE FROM pms WHERE id IN ()

What Am I doing wrong here? Going crazy over here..

A: 

You're not passing the right variable to your function. You need to call it with

if (isset($_POST['submit']))  
{
    delete($_POST['rowid']);
}
Željko Živković
+4  A: 

You need to use $_POST['rowid'], if you're grabbing that from post.

Also:

Sanitize your SQL!

thedz
Someone's going to submit your form with <input type="checkbox" name="rowid[]" value="SELECT id FROM pms" />.
Rafe
A: 

looks like you read some really old PHP manual where register_globals = on , you need to read the POST parameters in your case..

function delete($rowid) 
{
   $rowids = implode(", ",$rowid);
   $sql = "DELETE FROM pms WHERE id IN (".$rowids.")";
   print $sql;
}

if (isset($_POST['submit']))  
{
        delete($_POST['rowid']);
}
Gabriel Sosa