+ Post New Thread
Results 1 to 10 of 10
Coding Thread, PHP - Form POST script in Coding and Web Development; Hi, Info: PHP 5.2 Moodle 1.9.7 Apache 2 Windows Server 2003 Problem: I've created a form on a php page. ...
  1. #1
    BarryWAaMC's Avatar
    Join Date
    Oct 2009
    Posts
    22
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question PHP - Form POST script

    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:
    Code:
    $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.

  2. #2

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Be good to see the full script (or at least line numbers on the relevant file).

  3. #3

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    It means that there isn't a uname key in the $_POST array.

    Do this to see the contents of the $_POST array:

    Code:
    print_r($_POST);
    Array keys are case-sensitive. For example, Uname is different to uname.

  4. #4
    dwhyte85's Avatar
    Join Date
    Mar 2009
    Location
    Berkshire
    Posts
    1,219
    Thank Post
    159
    Thanked 147 Times in 132 Posts
    Rep Power
    103
    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?

  5. #5

    sonofsanta's Avatar
    Join Date
    Dec 2009
    Location
    Lincolnshire, UK
    Posts
    4,952
    Thank Post
    862
    Thanked 1,443 Times in 991 Posts
    Blog Entries
    47
    Rep Power
    616
    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

  6. Thanks to sonofsanta from:

    dwhyte85 (31st March 2010)

  7. #6
    BarryWAaMC's Avatar
    Join Date
    Oct 2009
    Posts
    22
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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!!!
    Code:
    // Form information
    echo ('You have '.$remaining.' options remaining.
    	
    ');
    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.
    Attached Files Attached Files

  8. #7

    sonofsanta's Avatar
    Join Date
    Dec 2009
    Location
    Lincolnshire, UK
    Posts
    4,952
    Thank Post
    862
    Thanked 1,443 Times in 991 Posts
    Blog Entries
    47
    Rep Power
    616
    methord="post" really oughta be method="post"

    Typos are the number one cause of all my PHP errors.

  9. #8

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    Quote Originally Posted by BarryWAaMC View Post
    methord="POST" action="/dev/optprocess.php">
    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.

  10. Thanks to webman from:

    dwhyte85 (31st March 2010)

  11. #9
    BarryWAaMC's Avatar
    Join Date
    Oct 2009
    Posts
    22
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I'd just spotted that.

    Now looking for a colleage to kick me very hard!!

    Thanks and sorry for wasting your time.

    Barry.

  12. #10

    sonofsanta's Avatar
    Join Date
    Dec 2009
    Location
    Lincolnshire, UK
    Posts
    4,952
    Thank Post
    862
    Thanked 1,443 Times in 991 Posts
    Blog Entries
    47
    Rep Power
    616
    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...

SHARE:
+ Post New Thread

Similar Threads

  1. javascript and php mail form
    By mikeglover in forum Coding
    Replies: 5
    Last Post: 19th January 2010, 01:32 PM
  2. Script AJAX form responses to RM easymail plus
    By MicrodigitUK in forum Scripts
    Replies: 0
    Last Post: 23rd November 2009, 11:19 AM
  3. [PHP] PHP Form Generator
    By _Bat_ in forum Web Development
    Replies: 1
    Last Post: 25th March 2009, 11:39 AM
  4. PHP form validation
    By thesk8rjesus in forum Web Development
    Replies: 10
    Last Post: 21st January 2009, 12:09 AM
  5. PHP script help
    By FN-GM in forum Web Development
    Replies: 18
    Last Post: 19th August 2008, 02:52 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •