BarryWAaMC Posted March 31, 2010 Posted March 31, 2010 Hi, Info: PHP 5.2 Moodle 1.9.7 Apache 2 Windows Server 2003 Problem: I've created a form on a php page. The form 'posts' three variables, (uname, tutor & newoption), on to the next script. I have used the following code to recover the information: $uname = $_POST["uname"]; $tutor = $_POST["tutor"]; $subjectid = $_POST["newoption"]; However, I get an error message as follows for each of the variables listed above: Notice: Undefined index: uname in D:\Web Server\moodle\dev\optprocess.php on line 12 If you need to see anything else, please ask. I am quite new to PHP so any help would be much apprechiated. Cheers, Barry.
Hightower Posted March 31, 2010 Posted March 31, 2010 Be good to see the full script (or at least line numbers on the relevant file).
webman Posted March 31, 2010 Posted March 31, 2010 It means that there isn't a uname key in the $_POST array. Do this to see the contents of the $_POST array: print_r($_POST); Array keys are case-sensitive. For example, Uname is different to uname.
dwhyte85 Posted March 31, 2010 Posted March 31, 2010 I thought it had to be single quotes as opposed to double quotes? e.g, 'uname' Even if it isn't posted it shouldn't error, you can still call the php file when posting nothing - no error but possibly a warning?
sonofsanta Posted March 31, 2010 Posted March 31, 2010 Be very handy to see the HTML form that is doing the submitting. Single quotes doesn't seem to be the problem - php.net's example uses double quotes Also check PHP: Variables From External Sources - Manual 1
BarryWAaMC Posted March 31, 2010 Author Posted March 31, 2010 Thanks all, OK I have added the Print instruction which returns: Array() I'm guessing this is not right! Here is the script of the form, which, if there is an error on, I'll kick myself very hard!!! // Form information echo ('You have '.$remaining.' options remaining. </pre><form name="selectoption" methord="POST" action="/dev/optprocess.php"> Please pick'); foreach($chors as $row2) { echo (''.$row2->subject.''); } echo (' </form><br>< I have attached the optprocess.php script as a text file. Because of the added lines, the error (notice) has changed to: Notice: Undefined index: uname in D:\Web Server\moodle\dev\optprocess.php on line 18 Thanks for your assistance with this. Barry.optprocess.txt
sonofsanta Posted March 31, 2010 Posted March 31, 2010 methord="post" really oughta be method="post" Typos are the number one cause of all my PHP errors.
webman Posted March 31, 2010 Posted March 31, 2010 The bolded word should be 'method' @dwhyte85 PHP quotes can either be single ' or double ", but there is a difference. Their use depends entirely what you want to achieve. 1
BarryWAaMC Posted March 31, 2010 Author Posted March 31, 2010 I'd just spotted that. Now looking for a colleage to kick me very hard!! Thanks and sorry for wasting your time. Barry.
sonofsanta Posted March 31, 2010 Posted March 31, 2010 All's well that ends well, and it always makes me smile to see such frustrating errors solved so simply chiefly because I remember it happening so much. I'm paranoid about semi-colons now; I use them wherever I can just to make sure I don't forget them in scripts...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now