HxM Graeme
HxM Graeme

Reputation: 117

Undefined Index PHP

I have been trying to get a form in HTML/PHP to process to into mysql / phpmyadmin table which is on the numyspace server but for reasons unknown to myself i get the following error message.

Notice: Undefined index: Username in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 14

Notice: Undefined index: Forename in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 15

Notice: Undefined index: Surname in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 16

Notice: Undefined index: Address in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 17

Notice: Undefined index: PostCode in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 18

Notice: Undefined index: EmailAddress in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 19

Notice: Undefined index: Password in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 20

Notice: Undefined index: DateOfCreation in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11034582/public_html/CaseProject/registerUserProcess.php on line 21 0INSERT INTO User (Username, Forename, Surname, Address, PostCode, EmailAddress, Password, DateOfCreation) VALUES ('', '', '', '', '', '', '', '')

As it stands where it says Insert into User () User is my table within the database that i would like the information to get inserted into. (all spellings and caps are in the correct place) i am not sure why all the values are blank as it looks like it hasn't gathered the information from the cells provided.

Any helps tips or pointers would be greatly appropriated thanks guys DateOfCreation is something im messing with atm maybe should take it out as its trying to convert the "i accept terms and conditions" check box to a time stamp to store the date when the user initially created an account. Code is in early stages and does not contain any validation in what so ever can provide code if needed just googled the error message and it seems there's alot of different types for this error message.

RegisterUserProcess.php
<?php
    include ("connection.inc.php");
    connect();

        $username = $_POST['Username'];
        $firstName = $_POST['Forename'];
        $lastName = $_POST['Surname'];
        $address = $_POST['Address'];
        $postCode = $_POST['PostCode'];
        $emailAddress = $_POST['EmailAddress'];
        $password = $_POST['Password'];
        $termsConditions = $_POST['DateOfCreation'];

            $sql="INSERT INTO User (Username, Forename, Surname, Address, PostCode, EmailAddress, Password, DateOfCreation)
            VALUES ('$username', '$firstName', '$lastName', '$address', '$postCode', '$emailAddress', '$password', '$termsConditions')";

                mysql_query($sql);
                print("Thank You " +$firstName+" "+$lastName + " You Have Successfully Created An Account!");
                echo $sql;

?>

RegisterUser2.php

?>
<p><b><h3>Welcome User Please Register</h3></b></p>
    <form action="registerUserProcess.php" id="registerUserForm" method="post" name="registerUserForm">
    *Username:                  
    <input name="username" type="text" size="16" />
    (must contain 8-16 characters with at least 1 number)<br /><br />
    *First name: 
    <input name="firstName" type="text" size="20" />
    *Last name: 
    <input name="lastName" type="text" size="30" />
    <br /><br />
    *Address: 
    <input name="address" type="text" size="50" />
    <br /><br />
    *Post Code:
    <input type="text" name="postCode" size="8" /><br /><br />
    *Email Address: 
    <input name="emailAddress" type="text" size="50" /><br /><br />
    *Password: 
    <input name="password" type="password" size="16" />
    (must contain 8-16 characters with at least 1 number)<br /><br />
    *Confirm Password: 
    <input name="confirmPassword" type="password" size="16" /><br /><br />
    *Accept Terms & Conditions: 
    <input type="checkbox" name="termsConditions" value="yes" /><br /><br />

    <input type="reset" name="resetForm" value="Reset" id="resetForm" />
    <input type="submit" name="submitUser" value="Submit" id="submitUser" />
    </form>
<?php

Upvotes: 2

Views: 3755

Answers (4)

Venkat Selvan
Venkat Selvan

Reputation: 3126

You should add these changes listed below

Note: $_POST['someelement'] is case-sensitive.

RegisterUserProcess.php

<?php
include ("connection.inc.php");
connect();
    $username = $_POST['username'];
    $firstName = $_POST['firstname'];
    $lastName = $_POST['lastname'];
    $address = $_POST['address'];
    $postCode = $_POST['postCode'];
    $emailAddress = $_POST['emailAddress'];
    $password = $_POST['password'];

And you have never specified input name dateofcreation in your html form. If you want the timestamp you should change dateofcreation field to timestamp and use now() in your query

    $termsConditions = $_POST['dateOfCreation'];

        $sql="INSERT INTO User (Username, Forename, Surname, Address, PostCode, EmailAddress, Password, DateOfCreation)
        VALUES ('$username', '$firstName', '$lastName', '$address', '$postCode', '$emailAddress', '$password', 'now()')";

            mysql_query($sql);
            echo "Thank You $firstName $lastName You Have Successfully Created An Account!";
            echo $sql;

?>

And your codes needs a lot of changes. It is a suggestion. If you are executing the code in same script then you should use isset

eg: if(isset($_REQUEST['submit']) { some code... } else { html form... }

Upvotes: 1

maialithar
maialithar

Reputation: 3123

$_POST keys are case-sensitive - you should change Username to username, Forename to forename, ... in your php code to match form fields' names.

Upvotes: 0

michaelotoole
michaelotoole

Reputation: 391

You will need to add an isset conditional around your tags (or something similar to that effect)

if (isset($DateOfCreation)) {
  // logic here...
}

Updated after reference to your updated question, you will need to change your code to the below (do this on every variable)

if (isset($_POST['Username'])) { 
  $username = $_POST['Username'];
}

Upvotes: 0

Alix Axel
Alix Axel

Reputation: 154513

Without seeing some code I can't be sure, but most probably you should change all your occurences of $Username to $_POST['Username'] (if you're using a form with the HTTP POST method), or $_GET['Username'] (if the data comes from the URL) - Username is just an example, of course.

Upvotes: 0

Related Questions