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
Can everyone (Microsoft, LibreOffice, Euro-Office, Apple) just come together and use one standard format?
I appreciate that everyone is turning around and saying, "but our format is better! Use our format!" but it just seems a bit pointless.
I just want to read and edit a document, for goodness sake...part of the reason I try and avoid the documents that people share is because it's too much of a headache. I don't care if you use Windows, Mac or Linux, but if I can't read the damned thing because of your preference I'm going to reply saying, "I can't open that and I'm not buying a new computer to read a 2 page document."
I noticed this was already happening within my organization; my teams location will change between remote and on-site without me having to do anything. Is it possible this is live already for select customers?
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