hi people
this might be a bit of a long post :-/
i have a table in my database called bbmaillist. its basically a list of email addresses. there are two columns bbml_id (auto increment int key field) and bbml_email (text).
i have this script called mail.php.
<?php
// database variables ***************************************
*blah*
// connect to the database **********************************
*blah*
// make da query
$SQL="SELECT * FROM bbmaillist ORDER BY bbml_id";
$query=mysql_db_query($database_name,$SQL);
$num_rows=mysql_num_rows($query);
// 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($query);
print("<tr><td bgcolor='#FF99FF'>");
print("<input name=eadd size=30 maxlength=70 value='".$array['bbml_email']."'>");
print("</td><td bgcolor='#FF99FF'>");
$bbml_id=$array['bbml_id'];
print('<input type="checkbox" name="echck['.$bbml_id.']" 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>");
//print('<input type="checkbox" name="echck['.$bbml_id.']" value="none">');
?>
it takes the entries from the database and puts them in an html table. each entry appears in an input text field with a checkbox next to it.
there are two submit buttons, one to delete and one to amend. both buttons go to this script:
<?php
// database variables ***************************************
*blah*
// connect to the 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 bbmaillist set bbml_email='.$HTTP_POST_VARS['eadd'] .' where '. $sql;
$query=mysql_db_query($database_name,$SQL);
echo $sql;
}
//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 bbmaillist where '.$sql;
$query=mysql_db_query($database_name,$SQL);
echo $sql;
}
?>
there is a problem somewhere, but im not sure where. i am not too hot at php - -i made this code with help from others.
basically it doesnt throw up any errors, but neither button changes the database.
when i echo the $sql for the amend part i get
UPDATE LOW_PRIORITY bbmaillist set bbml_email=text from text box where bbml_id="4"
...but it only gets the text from the last input field in the list, how can i make sure it selects the right one?
the code for deleting entries is fine (except it doesnt actually delete!) but when it comes to updating and i try to update more than one thing from the list at once it says:
UPDATE LOW_PRIORITY bbmaillist set bbml_email= text from text box where bbml_id="6" or bbml_id="11"
so i need to get it to include the new text for every entry in the list that was checked.
thanks in advance, sorry for the lengthy post. (does vbcode work on here? guess i'll find out...)