I've written a simple script in PHP that allows users to submit their ascii art to the site. Each new submission gets an 'approved' value of 0 until it is reviewed and approved by myself. I've set up a basic admin area that pulls all the records from the database that have not yet been approved and displays them on screen. Below each record is a checkbox with a dynamically generated name in the form: chk[iD], where [iD] is the auto-incremented id of the record.
I'm having trouble determining whether a checkbox has been ticked or not when submitting my form, which queries the database. I've got the following code so far, but it does not seem to work (all checkboxes are read as 'checked'!): :
$approved=0;
if($_POST['submit'])
{
$i=0;
while($i<$records_size)
{
$chkBox="chk" .$records[$i];
#if checkbox of current record's id is checked
if($chkBox!="")
{
#create query
$sql="UPDATE asciiart SET approved=1 WHERE id=$records[$i]";
#execute query
$result=mysql_query($sql,$connection);
$approved++;
}
$i++;
}
$url=$PHP_SELF ."?processed";
print "<html><head><meta http-equiv='Refresh' content='1; url=$url'></head></html>";
die("$approved of $records_size approved");
}
The if($chkBox!="") part of the code is obviously what's causing the problem, but I don't know to change it. Were it a VB app I would have done if chkBox[id].checked=false
This is so the rich and powerful get world class models before the rest of us, the reality is dumb politicians and rich people don't realize that dense models are on there way out and MOE models are coming in, meaning after PCI-E 8 spec goes live, we run via streaming world class frontier models on a 16gb graphics card.
Question
alset_alokin
Hi guys,
I've written a simple script in PHP that allows users to submit their ascii art to the site. Each new submission gets an 'approved' value of 0 until it is reviewed and approved by myself. I've set up a basic admin area that pulls all the records from the database that have not yet been approved and displays them on screen. Below each record is a checkbox with a dynamically generated name in the form: chk[iD], where [iD] is the auto-incremented id of the record.
I'm having trouble determining whether a checkbox has been ticked or not when submitting my form, which queries the database. I've got the following code so far, but it does not seem to work (all checkboxes are read as 'checked'!): :
$approved=0; if($_POST['submit']) { $i=0; while($i<$records_size) { $chkBox="chk" .$records[$i]; #if checkbox of current record's id is checked if($chkBox!="") { #create query $sql="UPDATE asciiart SET approved=1 WHERE id=$records[$i]"; #execute query $result=mysql_query($sql,$connection); $approved++; } $i++; } $url=$PHP_SELF ."?processed"; print "<html><head><meta http-equiv='Refresh' content='1; url=$url'></head></html>"; die("$approved of $records_size approved"); }The if($chkBox!="") part of the code is obviously what's causing the problem, but I don't know to change it. Were it a VB app I would have done if chkBox[id].checked=false
The main page is at: http://www.cyberiapc.com/asciiart.php and the admin area is at http://www.cyberiapc.com/asciiart_pending.php
I'd appreciate any pointers?
Thanks.
CoreLEx
Link to comment
https://www.neowin.net/forum/topic/87239-checkboxes-and-php/Share on other sites
12 answers to this question
Recommended Posts