Page 1 of 1
Form with checkboxes...[topic solved]
Posted: Wed Oct 17, 2007 10:59 am
by SirChick
I have a form with 3 check boxes but in my php process im getting this:
Notice: Undefined index: CheckBox1 in C:\xampp\htdocs\lettermanager.php on line 8
Notice: Undefined index: CheckBox2 in C:\xampp\htdocs\lettermanager.php on line 9
Notice: Undefined index: CheckBox3 in C:\xampp\htdocs\lettermanager.php on line 10
This is the check box in the form:
Code: Select all
<input type="checkbox" id="Checkbox1" name="Checkbox1" value="" style="position:absolute;left:100px;top:88px;z-index:0">
<input type="checkbox" id="Checkbox2" name="Checkbox2" value="" style="position:absolute;left:100px;top:255px;z-index:1">
<input type="checkbox" id="Checkbox3" name="Checkbox3" value="" style="position:absolute;left:100px;top:427px;z-index:2">
Then my php process is:
Code: Select all
$MessageOne = $_POST['CheckBox1'];
$MessageTwo = $_POST['CheckBox2'];
$MessageThree = $_POST['CheckBox3'];
These are the 3 lines causing the problem but i do not see why =/
Posted: Wed Oct 17, 2007 11:09 am
by Josh1billion
CheckBox1, CheckBox2, and CheckBox3 will only be set if the value is checked, otherwise the PHP form handler won't even know the checkboxes existed.
So change your PHP processing code to this instead:
Code: Select all
if (isset($_POST['CheckBox1']))
$MessageOne = true;
else
$messageOne = false;
if (isset($_POST['CheckBox2']))
$MessageTwo = true;
else
$messageTwo = false;
if (isset($_POST['CheckBox3']))
$MessageThree = true;
else
$messageThree = false;
And those values will be true or false depending on whether the checkbox was ticked by the user.
Posted: Wed Oct 17, 2007 11:14 am
by SirChick
Do i still need the:
Code: Select all
$MessageOne = $_POST['CheckBox1'];
$MessageTwo = $_POST['CheckBox2'];
$MessageThree = $_POST['CheckBox3'];
Cos at the moment i got this:
Notice: Undefined variable: MessageOne in C:\xampp\htdocs\lettermanager.php on line 24
Notice: Undefined variable: MessageTwo in C:\xampp\htdocs\lettermanager.php on line 29
Notice: Undefined variable: MessageThree in C:\xampp\htdocs\lettermanager.php on line 35
Posted: Wed Oct 17, 2007 11:16 am
by Josh1billion
Nope, replace that part with the code I gave you.
Posted: Wed Oct 17, 2007 11:22 am
by SirChick
Ok done that but my code isn't working .. well its not a php problem but an sql problem... i think:
Code: Select all
$DeleteMessageOne ="UPDATE messages SET Status = '1' WHERE Reciever= '{$_SESSION['Current_User']}' AND MessageID='$MessageIDOne'";
$result = mysql_query($DeleteMessageOne) or die(mysql_error());
No error is produced but it doesnt set status to 1.
If i set this:
Code: Select all
if (isset($_POST['CheckBox1']))
$MessageOne = true;
It doesnt equal true when i echo it =/
Could it be my form ?
Code: Select all
<form name="" method="POST" action="lettermanager.php" id="Form1" onsubmit="return ValidateForm1(this)">
<input type="checkbox" id="Checkbox1" name="Checkbox1" value="" style="position:absolute;left:100px;top:88px;z-index:0">
<input type="checkbox" id="Checkbox2" name="Checkbox2" value="" style="position:absolute;left:100px;top:255px;z-index:1">
<input type="checkbox" id="Checkbox3" name="Checkbox3" value="" style="position:absolute;left:100px;top:427px;z-index:2">
<input type="submit" id="Button1" name="Button1" value="Delete Selected" style="position:absolute;left:30px;top:478px;width:119px;height:24px;z-index:3">
</form>
Posted: Wed Oct 17, 2007 11:28 am
by Josh1billion
In your SQL, you have $MessageIDOne, but in your PHP, you have $MessageOne. If you're passing that variable to an SQL query, you'll probably want to set the values to something like 1 instead of true and 0 instead of false.
And yep, the echoing thing is a problem with your form. You have "Messagebox1" in your form but "MessageBox1" in the PHP code. The B is capital in the PHP code and lowercase in the form. Same with MessageBox2 and MessageBox3.
Posted: Wed Oct 17, 2007 11:29 am
by SirChick
$MessageOne is to set true or false..
then if true do the sql.. and $MessageIDOne is carried over from a session so that the sql knows which ID it is meant to be updating...
Code: Select all
<form name="" method="POST" action="lettermanager.php" id="Form1" onsubmit="return ValidateForm1(this)">
<input type="checkbox" id="Checkbox1" name="Checkbox1" value="" style="position:absolute;left:100px;top:88px;z-index:0">
<input type="checkbox" id="Checkbox2" name="Checkbox2" value="" style="position:absolute;left:100px;top:255px;z-index:1">
<input type="checkbox" id="Checkbox3" name="Checkbox3" value="" style="position:absolute;left:100px;top:427px;z-index:2">
<input type="submit" id="Button1" name="Button1" value="Delete Selected" style="position:absolute;left:30px;top:478px;width:119px;height:24px;z-index:3">
</form>
Then i have:
Code: Select all
//created on the same page as the form is on
$MessageIDOne = $_SESSION['MessageOneID'];
if (isset($_POST['CheckBox1']))
$MessageOne = true;
else
$MessageOne = false;
if ($MessageOne == true) {
$DeleteMessageOne ="UPDATE messages SET Status = '1' WHERE Reciever= '{$_SESSION[Current_User]}' AND MessageID='$MessageIDOne'";
$result = mysql_query($DeleteMessageOne) or die(mysql_error());
}
Posted: Wed Oct 17, 2007 11:36 am
by Josh1billion
Like I said at the end of my last post, change the b's in "Checkbox" in the form to capital B's like they are in "CheckBox" in the PHP code.
Posted: Wed Oct 17, 2007 11:47 am
by SirChick
Oh right you said messagebox on the first time and confused me lol

Posted: Wed Oct 17, 2007 12:00 pm
by Josh1billion
Oops, lol.. I'm mostly a C++ programmer, so I've used MessageBoxes a lot more than I've used Checkboxes.
Is it working now though?
Posted: Wed Oct 17, 2007 12:02 pm
by SirChick
yup thanks.
Posted: Wed Oct 17, 2007 12:09 pm
by Josh1billion
You're welcome.
