Jump to content

a little help please


divinedesigns1
 Share

Recommended Posts

i need a little help here, i keep getting this error from the localhost

Notice: Undefined index: fname in C:\wamp\www\promoform.php on line 4
i checked both the php and html and everything match up and is saved inside of the www folder This is the php "its just a small demo"
<?phpinclude_once "myconnect.php";$fname = $_POST['fname'];$lname = $_POST['lname'];$email = $_POST['email'];$company = $_POST['company'];$mobile = $_POST['mobile'];$query = "INSERT INTO demo(first_name, last_name, phone, email, company_name)" . "VALUE('$fname', '$lname', '$mobile', '$email' , '$company')";$result = mysqli_query($con, $query);mysqli_close($con);echo "Thank You For Filling Out the Fill2Win form";?>

and this is the html

<form action="" method="post"><fieldset><legend>Fill to Win Promotion</legend><table align="center" border="0" width="284"><tr><td width="128" align="right"><label for="fname">First Name: </label></td><td width="146"><input type="text" name="fname" id="fname" /></td></tr><tr><td align="right"><label for="lname">Last Name: </label></td><td><input type="text" name="lname" id="lname" /></td></tr><tr><td align="right"><label for="mobile">Mobile/Phone: </label></td><td><input type="text" name="mobile" id="mobile" /></td></tr><tr><td align="right"><label for="email">Email Address: </label></td><td><input type="email" name="email" id="email" /></td></tr><tr><td align="right"><label for="company">Company Name: </label></td><td><input type="text" name="company" id="company" /></td></tr><tr><td></td><td><input type="submit" name="submit" id="submit" value="Submit"  /></table></form>

besides me not adding the self server php into the [ action ]

  • Like 1
Link to comment
Share on other sites

If this is posting to itself with self server, when the page first loads it will look for post value from 'fname', as none of these have been submitted yet! it will come up with error for first $_POST reference Notice: Undefined index: fname use isset to check if 'submit' has been sent as post value

if(isset($_POST['submit'])){$fname = $_POST['fname'];$lname = $_POST['lname'];$email = $_POST['email'];$company = $_POST['company'];$mobile = $_POST['mobile'];$query = "INSERT INTO demo(first_name, last_name, phone, email, company_name)" . "VALUE('$fname', '$lname', '$mobile', '$email' , '$company')";$result = mysqli_query($con, $query);mysqli_close($con);echo "Thank You For Filling Out the Fill2Win form";}

Link to comment
Share on other sites

Also, your VALUE statement in the query isn't concatenated.

Edited by niche
Link to comment
Share on other sites

If this is posting to itself with self server, when the page first loads it will look for post value from 'fname', as none of these have been submitted yet! it will come up with error for first $_POST reference Notice: Undefined index: fname use isset to check if 'submit' has been sent as post value
if(isset($_POST['submit'])){$fname = $_POST['fname'];$lname = $_POST['lname'];$email = $_POST['email'];$company = $_POST['company'];$mobile = $_POST['mobile'];$query = "INSERT INTO demo(first_name, last_name, phone, email, company_name)" . "VALUE('$fname', '$lname', '$mobile', '$email' , '$company')";$result = mysqli_query($con, $query);mysqli_close($con);echo "Thank You For Filling Out the Fill2Win form";}

ok thanks, and i fixed the problem with a "@" before the "$_POST" which work, it seem that wamp have a little problem. thanks again dsone
Link to comment
Share on other sites

Guest So Called

Also note that you would need to add security checking before using that form on a publicly accessible web page. Otherwise it just invites a SQL injection attack.

Link to comment
Share on other sites

Also note that you would need to add security checking before using that form on a publicly accessible web page. Otherwise it just invites a SQL injection attack.
its a demo like i said above
This is the php "its just a small demo"
Link to comment
Share on other sites

i did what you said to do but im still getting the same errors

Link to comment
Share on other sites

If it says undefined index that means you're trying to access an array item that isn't there. If the array you're trying to access is $_POST, and the item you're looking for isn't there, then the 2 possibilities are either that you have the name wrong, or the form hasn't been submitted yet. If you're sure the names are right, then you need to check that the form was submitted like dsonesuk showed. Those are the only 2 possibilities. If you added dsonesuk's code and you're still getting the error then you're using the wrong name. You can use print_r to see what was submitted if you want to verify: print_r($_POST);

Link to comment
Share on other sites

Guest So Called
its a demo like i said above
"its just a small demo" implies that it's a demonstration for somebody, and does not logically require that it is not publicly accessible. Also, other people may read this topic in the future and may not be aware of security concerns. It is always a good idea to remind everybody to think about security when designing web pages. I'm sorry if it appeared that I implied any lack of knowledge on your part.
i did what you said to do but im still getting the same errors
Please post your most recent code.
Link to comment
Share on other sites

"its just a small demo" implies that it's a demonstration for somebody, and does not logically require that it is not publicly accessible. Also, other people may read this topic in the future and may not be aware of security concerns. It is always a good idea to remind everybody to think about security when designing web pages. I'm sorry if it appeared that I implied any lack of knowledge on your part. Please post your most recent code.
it will have security dude/girl, im just making sure everything else work -_-anyway, this is my latest code from lastnight before i fell asleep
<?phpinclude_once "myconnect.php";if(isset($_POST['submit'])){    $firstname = @$_POST['firstname'];    $lastname = @$_POST['lastname'];    $email = @$_POST['email'];    $company = @$_POST['company'];    $mobile = @$_POST['mobile'];    $output_form = false;}if(empty($firstname) && empty($lastname) && empty($email) && empty($mobile)){    echo "Please Fill In The Following Fields: " . "<br />" . $firstname . "<br />" . $lastname . "<br />" . $email . "<br />" . $company . "<br />";    echo "Thank You";    $output_form = true;}if(!empty($firstname) && empty($lastname) && empty($email) && empty($mobile)){    echo "Please Fill In The Following Fields: " . "<br />" . $lastname . "<br />" . $email . "<br />" . $mobile . "<br />";    echo "Thank You";    $output_form = true;}if(!empty($firstname) && !empty($lastname) && empty($email) && empty($mobile)){    echo "Please Fill In The Following Fields: " . "<br />" . $email . "<br />" . $mobile . "<br />";    echo "Thank You";    $output_form = true;}if(!empty($firstname) && !empty($lastname) && !empty($email) && empty($mobile)){    echo "Please Fill In The Following Fields: " . "<br />" . $mobile . "<br />";    echo "Thank You";    $output_form = true;}else {    $output_form = true;}if(!empty($firstname) && !empty($lastname) && !empty($email) && !empty($mobile)){    $query = "INSERT INTO demo(first_name, last_name, phone, email, company_name)" . "VALUE('$firstname', '$lastname', '$mobile', '$email' , '$company')";$result = mysqli_query($con, $query);}mysqli_close($con);if($output_form){?><form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"><fieldset><legend>Fill to Win Promotion</legend><table align="center" border="0" width="284"><tr><td width="128" align="right"><label for="fname">First Name: </label></td><td width="146"><input type="text" name="firstname" id="firstname" value="<?php echo '$firstname'; ?>" /></td></tr><tr><td align="right"><label for="lname">Last Name: </label></td><td><input type="name" name="lastname" id="lastname" value="<?php echo '$lastname'; ?>" /></td></tr><tr><td align="right"><label for="mobile">Mobile/Phone: </label></td><td><input type="text" name="mobile" id="mobile" value="<?php echo '$mobile'; ?>" /></td></tr><tr><td align="right"><label for="email">Email Address: </label></td><td><input type="email" name="email" id="email" value="<?php echo '$email'; ?>" /></td></tr><tr><td align="right"><label for="company">Company Name: </label></td><td><input type="text" name="company" id="company" /></td></tr><tr><td></td><td><input type="submit" name="submit" id="submit" value="Submit"  /></table></form><?php}?>

Link to comment
Share on other sites

so that code works, its something to do with wamp i have on my desktop, now its time to add the security and whats not to it thanks guys

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...