hi guys
im trying to build a page which will allow me to update a table in my mysql database.
the table has two columns bbml_id (key auto increment integer) and bbml_email (text).
i have created a form which lists each email inside an input text field with a checkbox next to it.
it looks like this:
submissions from this form go to the following script:
i built this code with the help of other people and patching together other scripts that i had. its not quite working at the moment and i dont really have the knowledge to fix it.
the delete part of the script works fine, the problem is with the amend part.
basically the eadd variable from the first script never seems to arrive at the second. i think the problem is that the array is not created peoperly somehow, but im not sure i dont know php well enough to debug this thing ....
also, lets assume that we managed to get the eadd variable into the second script, it somehow needs to go into that while() loop so that i can amend multiple entries at the same time.
if anyone could give me any help i would be most grateful - please bear in mind that im a newbie and need things explained well X-) thanks .
Lentil
give me all your lentils
im trying to build a page which will allow me to update a table in my mysql database.
the table has two columns bbml_id (key auto increment integer) and bbml_email (text).
i have created a form which lists each email inside an input text field with a checkbox next to it.
it looks like this:
Code:
// set connection variables
***blah
// connect and select database
***blah
// make da query
$SQL="SELECT * FROM $table_name ORDER BY bbml_id";
$result=@mysql_query($SQL, $connection)
or die("Couldn't execute query.");
$num_rows=mysql_num_rows($result);
// build a table
print("<table cellspacing='0' cellpadding='0'><form method='POST' action='delete.php'>");
for ($a=0; $a < $num_rows; $a++)
{
$array=mysql_fetch_array($result);
print("<tr><td bgcolor='#FF99FF'>");
$add_num=$array['bbml_email'];
print("<input name='eadd['.$add_num.']' size='30' maxlength='70' value='".$array['bbml_email']."'>");
print("</td><td bgcolor='#FF99FF'>");
$chck_num=$array['bbml_id'];
print('<input type="checkbox" name="echck['.$chck_num.']" value="none">');
print("</td></tr>");
}
print("<tr><td><br><input type='submit' value='amend' name='amend'><input type='submit' value='delete' name='delete'></td></tr></form></table>");
submissions from this form go to the following script:
Code:
// set connection variables
***blah
// connect and select database
***blah
//AMEND ***********************************************
if(isset($HTTP_POST_VARS['amend'])){
//as long as we have elements in our array
while(list($key)=each($HTTP_POST_VARS['echck']))
{
$SQL.=" or bbml_id=" .$key;
}
//lets cut the first ' or' part
$SQL=substr($SQL, 4);
//lets complete the query
$SQL="UPDATE LOW_PRIORITY $table_name set bbml_email='".$HTTP_POST_VARS['eadd']."' where ". $SQL;
$result=@mysql_query($SQL, $connection)
or die("Couldn't execute query because:".mysql_error());
}
//DELETE ***********************************************
elseif(isset($HTTP_POST_VARS['delete'])){
//as long as we have elements in our array
while(list($key)=each($HTTP_POST_VARS['echck']))
{
$SQL.=" or bbml_id=" .$key;
}
//lets cut the first ' or' part
$SQL=substr($SQL, 4);
//lets complete the query
$SQL="DELETE from $table_name where ".$SQL;
$result=@mysql_query($SQL, $connection)
or die("Couldn't execute query because:".mysql_error());
}
i built this code with the help of other people and patching together other scripts that i had. its not quite working at the moment and i dont really have the knowledge to fix it.
the delete part of the script works fine, the problem is with the amend part.
basically the eadd variable from the first script never seems to arrive at the second. i think the problem is that the array is not created peoperly somehow, but im not sure i dont know php well enough to debug this thing ....
also, lets assume that we managed to get the eadd variable into the second script, it somehow needs to go into that while() loop so that i can amend multiple entries at the same time.
if anyone could give me any help i would be most grateful - please bear in mind that im a newbie and need things explained well X-) thanks .
Lentil
give me all your lentils