PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 8:40 am
I'm using form tags in HTML. One example of such a tag is this:-
Code: Select all
<input name="MonssRaiders" type="checkbox" id="MonssRaiders" value="checkbox">
I have all the other elements, form action=buy.php etc, now, my buy.php basicly looks like this...
Code: Select all
if (!$_POST["MonssRaiders"]=="")
{
$Rcost++;
$MonssRaidersarmy++;
}
Now, here comes the problem. When I run it I get an '
Notice: Undefined index: MonssRaiders in c:\program files\easyphp1-7\www\buy.php on line 81' error.
Any help is apprechiated.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 8:43 am
what is the method of the form?
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 8:44 am
Post...
The HTML is <form action="buy.php" method="POST">.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 8:45 am
it would be better showing your actually code, because it is impossible to tell from what you have provided.
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 8:51 am
The HTML with all stuff like images and tables taken out, and a bit of PHP:
Code: Select all
<form action="buy.php" method="POST">
<input name="MonssRaiders" type="checkbox" id="MonssRaiders" value="checkbox">
<select name="MonssRaiders-list" id="MonssRaiders-list">
<?php
if (isset($_COOKIEї"MTGCookie"]))
{
for ($i=0; $i<=$nooflands; $i++)
{
$a=file_get_contents($_COOKIEї"MTGCookie"] . "land" . $i . ".txt");
echo "<option>" . $a . "</option>";
}
}
?>
</select>
<input type="submit"/>
</form>
The code on Buy.php:
Code: Select all
if (!$_POST["MonssRaiders"]=="")
{
$Rcost++;
$MonssRaidersarmy++;
}
if (!$_POST["MonssRaiders"]=="")
{
$Rcost++;
$MonssRaiders=$_POST["MonssRaiders-list"];
}
}
?>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 8:52 am
What version of PHP you running?
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 8:53 am
I'm running 4.3.3
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 8:58 am
are you getting the error when the checkbox is selected or deselected or both?
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 9:01 am
I'm getting it with both instances.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 9:04 am
try changing your PHP to this
Code: Select all
if (isset($_POST["MonssRaiders"]))
{
$Rcost++;
$MonssRaidersarmy++;
}
if (isset($_POST["MonssRaiders"]))
{
$Rcost++;
$MonssRaiders=$_POST["MonssRaiders-list"];
}
}
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 9:09 am
I've changed the code, and now it doens't run though what's inside the If Staments. Not that it did before, but still....
I'm starting to suppect that for some reason the data's not being send though the form. Not sure why.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 9:15 am
put this at the top of buy.php
Code: Select all
echo "<pre>";
print_r($_POST);
echo "</pre>";
THen submit the form once with the check box selected and once without it selected and post back what is outputted to the browser.
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 9:22 am
Unchecked:-
Array
(
[Mon's_Raiders-list] =>
)
Checked:-
Array
(
[Mons's_Raiders] => checkbox
[Mon's_Raiders-list] =>
)
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Wed Feb 18, 2004 9:26 am
okay, now we are getting somewhere.
Are you sure your form elements ar named correctly. In you posts, you said the checkbox was named "MonssRaiders", but the results you just posted say that the checkbox is actually named "Mons's_Raiders".
So you would need to change your code to the following
Code: Select all
if (isset($_POST["Mons's_Raiders"]))
{
$Rcost++;
$MonssRaidersarmy++;
}
if (isset($_POST["Mons's_Raiders"]))
{
$Rcost++;
$MonssRaiders=$_POST["Mon's_Raiders-list"];
}
}
And it is probably best not to use single quotes in form names, will just lead to headaches at some point.
Mark
desinc
Forum Newbie
Posts: 16 Joined: Sat Jan 31, 2004 5:13 pm
Post
by desinc » Wed Feb 18, 2004 9:32 am
Yeah, that works.
However, the Mon's Raiders was the old name for it before I decided to take out the ' because I suddenly decided that the single quote would cause me problems. Obvisoly, I've must have madd a mistake somewhere changing the HTML code.
Thanks for your help.