Forums
This topic is locked
Created a form in php, but keep getting: PHP Notice: Undefined index:
Posted 20 Mar 2012 10:06:40
1
has voted
20 Mar 2012 10:06:40 james thomas posted:
Hi i am trying to create a login form for my e commerce site: i have created 3 php files: config, registration and reg. the error i get is for the reg file. Below is the code which i have used to put the data into my database but it doesnt go in. <?php
include"config.php";
$username = $_POST['username'];
$password = md5($_POST['password']);
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$telephone_number = $_POST['telephone_number'];
$email = $_POST['email'];
$insert = 'INSERT into customer(username, password, first_name, last_name, address, town, county, postcode, telephone_number, email) VALUES ["'.$username.'","'.$password.'", "'.$first_name.'", "'.$last_name.'", "'.$address.'", "'.$town.'", "'.$county.'", "'.$postcode.'", "'.$telephone_number.'", "'.$email.'"]';
mysql_query($insert);
?>
The error i get when i fill out the form is:
PHP Notice: Undefined index: username in C:\inetpub\wwwroot\boutique\reg.php on line 5
Please can someone help me I am quite confused. thank You
Replies
Replied 20 Mar 2012 10:10:26
20 Mar 2012 10:10:26 james thomas replied:
forgot to state that line 5 is the $username....
Replied 26 Mar 2012 12:37:27
26 Mar 2012 12:37:27 Roddy Dairion replied:
These notice occurs when the value you are trying to store in a variable has not been set i.e. the POST username has not been sent thus creating an undefined POST username. It is recommended to use isset. E.g.
Hope this helps.
Note: This should apply to every single post.
Roddy.
$username=isset($_POST['username']) : $_POST['username'] ? "";
Hope this helps.
Note: This should apply to every single post.
Roddy.