Re: Query String

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Hello Vichea,

In your HTML you should have form fields with names indicating that they are an array by using square brackets [] after the name - something like this:

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	<input type="checkbox" name="id[]" value="a" /> a 
	<input type="checkbox" name="id[]" value="b" /> b 
	<input type="checkbox" name="id[]" value="c" /> c 
	<input type="checkbox" name="id[]" value="d" /> d 
	<input type="submit" name="submit" />
</form>

When the submit button is clicked it creates a URI query string something like this:

/path/to/page.php?id[]=a&id[]=b&id[]=c&submit=Submit+Query

Then in your PHP script you can treat $_GET['id'] as an array with such constructs as 'foreach' and the various array functions. But if you want to run the delete SQL command try something like this (remembering to eradicate SQL injection, empty arrays and non-array objects first):

$ids = substr(implode(',', $_GET['id']), 0, -1);
$query = mysql_query("DELETE FROM table_name WHERE id IN ($ids)") or die(mysql_error());

That should do it. I hope this helps.

-- Shadow Caster


--- In php-objects@xxxxxxxxxxxxxxx, Sovichea SOU <svch_sou@...> wrote:
>
> Hi,
> 
> I want to delete multi records where id=5653, 56581,and 56587.
> 
> http://localhost/news/index.php?cID=56534&cID=56581&cID=56587&submit=Verify
> 
> how to split cID from the url?
> how to delete those records?
> 
> 
> Many thanks
> 
> Vichea
> 
> 
> [Non-text portions of this message have been removed]
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux