2

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
0

4 Answers 4

1

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... }

Sign up to request clarification or add additional context in comments.

Comments

0

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'];
}

10 Comments

so in pseudo code something along the lines of: if check box ticked then stamp date?
Hi Graeme, To the above comment, yep correct! The issue you are getting is more generic really, PHP has deprecated register globals (you can manually turn it back on but it is not really good from a practicle and coding standards point of view). You should also really pass your variables through an escaping routine to remove potentially damaging injection. Something along the lines of mysql_real_escape_string($var).
I will look into what real escape is and how i can use it. Just sounds abit overwhelming i need to grasp the concept again as i havnt touched web in a couple years and getting it mixed up with java. Thanks for the help
@michaelotoole This problem has nothing to do with globals - notice provided in the question says everything: "Undefined index". This is proper behavior as there is no field with name Username, Forename, ...
the things you said Username Forename Surname are all the correct names of the fields within mysql table within phpmyadmin. Really dont understand where iv gone wrong
|
0

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.

Comments

0

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

4 Comments

on $username = $_POST['Username']; $username is my text field? and $_POST['Username'] is the row within the phpmyadmin database? if so then the cases are correct? thanks
No. $username is your variable and $_POST['username'] is a value received from your form (field with name: username). These values have nothing to do with your database.
iv given my text areas a name/id of e.g. username, firstName.. do i need to declear the variables on my RegisterUser2.php page? something like username = get.username? or am i thinking java again sorry
Your form fields' names are also keys for the $_POST array. Since they are case-sensitive, you can't get value of $_POST['Username'] because there is no field with name Username in your form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.