List Info

Thread: note 78423 added to control-structures.foreach




note 78423 added to control-structures.foreach
user name
2007-10-11 07:12:28
Hi guys, I created a form, that shows people who signed up
for an event. So I want to put a checkbox near every people
name, so when I click the checkboxs the names are deleted
from the DB. Here is the code that shows the output:
[code]

$Result = mysql_query("SELECT * FROM vlist ORDER BY
'id'",$link);
echo "<form name='check' action='checked.php'
method='post'>";
echo "<table name='app' cellpadding='0'>";
echo "<tr bgcolor='#eeeeee'>";
echo "<th name='id'></th><th
name='eso'>ESO Username</th><th
name='email'>e-mail</th><th
name='country'>country</th><th
name='contacted'>Contacted</th>";
echo "</tr>";

while ($Row = mysql_fetch_row($Result))
{
if ($Row[4]== "true") { $Row[4] = "<img
src='check.gif'>";}
if ($Row[4]== "false") { $Row[4] = "<img
src='x.gif'>";}
printf ("<tr><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td><input
name='to_delete[]' value='$Row[0]'
type='checkbox'/></td></tr>",
$Row[0], $Row[1], $Row[2], $Row[3], $Row[4] );
}

echo "</table>";
echo "<input type='submit' name='submit'
value='Submit'>";
echo "</form>";
[/code]
And here is the delete page:
[code]
// Retrieve all keys that point to "true"
$contacted = array_keys($_POST, true);

if ($contacted == true) {
  $condition = "id = " . $value;
  while ($value = next($contacted)) {
    $condition .= " OR id = $value";
  }

  // Create & execute query
  $query = "DELETE FROM vlist WHERE " .
$condition;
  $result = mysql_query($query);
[/code]
But as you might have guessed it doesnt work. THanks for
your help!
----
Server IP: 69.147.83.197
Probable Submitter: 65.92.214.210
----
Manual Page -- http://www.php.net/manual/en/control-structures.forea
ch.php
Edit        -- https://master
.php.net/note/edit/78423
Del: integrated  -- h
ttps://master.php.net/note/delete/78423/integrated
Del: useless     -- http
s://master.php.net/note/delete/78423/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78423/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78423/spam
Del: non-english -- 
https://master.php.net/note/delete/78423/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78423/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78423
Reject      -- https://mast
er.php.net/note/reject/78423
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


note 78423 rejected from control-structures.foreach by nlopess
user name
2007-10-21 16:55:47
Note Submitter: arasam1 at yahoo dot com 

----

Hi guys, I created a form, that shows people who signed up
for an event. So I want to put a checkbox near every people
name, so when I click the checkboxs the names are deleted
from the DB. Here is the code that shows the output:
[code]

$Result = mysql_query("SELECT * FROM vlist ORDER BY
'id'",$link);
echo "<form name='check' action='checked.php'
method='post'>";
echo "<table name='app' cellpadding='0'>";
echo "<tr bgcolor='#eeeeee'>";
echo "<th name='id'></th><th
name='eso'>ESO Username</th><th
name='email'>e-mail</th><th
name='country'>country</th><th
name='contacted'>Contacted</th>";
echo "</tr>";

while ($Row = mysql_fetch_row($Result))
{
if ($Row[4]== "true") { $Row[4] = "<img
src='check.gif'>";}
if ($Row[4]== "false") { $Row[4] = "<img
src='x.gif'>";}
printf ("<tr><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td
align='center'>%s</td><td><input
name='to_delete[]' value='$Row[0]'
type='checkbox'/></td></tr>",
$Row[0], $Row[1], $Row[2], $Row[3], $Row[4] );
}

echo "</table>";
echo "<input type='submit' name='submit'
value='Submit'>";
echo "</form>";
[/code]
And here is the delete page:
[code]
// Retrieve all keys that point to "true"
$contacted = array_keys($_POST, true);

if ($contacted == true) {
  $condition = "id = " . $value;
  while ($value = next($contacted)) {
    $condition .= " OR id = $value";
  }

  // Create & execute query
  $query = "DELETE FROM vlist WHERE " .
$condition;
  $result = mysql_query($query);
[/code]
But as you might have guessed it doesnt work. THanks for
your help!

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )