I can't figure out the error here

0 Kumi Festus · October 8, 2014
I tried to save html form data into mysql database. The info was actually saved in the database. Then why the error?
I hope someone can figure out this for.
<!doctype html>
<html>
<head>
<title>Message Receiving Page</title>
</head>
<body>
<h1>Hello</h1>
<form action="message.php" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Contact Us</legend>
<label for="name">Name:</label><br/>
<input type="text" name="FullName"/><br/>
<label for="phone">Phone Number:</label><br/>
<input type="text" name="PhoneNumber"/><br/>
<label for="gender">Gender</label><br/>
<input type="radio" name="Gender" value="Male"/>Male
<input type="radio" name="Gender" value="Female"/>Female<br/>
<label for="message">Message</label><br/>
<textarea rows="4" cols="30" name="Message"></textarea><br/>
<input type="submit" name="submit" value="Save Message"/>
<input type="reset" value="Reset"/>
</fieldset>
</form>
<?php
$name = mysql_real_escape_string($_POST['FullName']);
$phone = mysql_real_escape_string($_POST['PhoneNumber']);
$gender = mysql_real_escape_string($_POST['Gender']);
$message = mysql_real_escape_string($_POST['Message']);
 mysql_connect('localhost','root','') or die(mysql_error());
 mysql_select_db('data1')or die(mysql_error());
 
 
 $insert = "INSERT INTO users1
(FullName,PhoneNumber,Gender,Message)
VALUES('$name','$phone','$gender','$message')";
 if(!mysql_query($insert)){
  die("Data could not be save".mysql_error());
   }else{
  echo "Data Saved To database";
  }
 

 

?>
</body>
</html>

The Error From The browser
Notice: Undefined index: FullName in C:\xampp\htdocs\BMNetwork\message.php on line 25

Notice: Undefined index: PhoneNumber in C:\xampp\htdocs\BMNetwork\message.php on line 26

Notice: Undefined index: Gender in C:\xampp\htdocs\BMNetwork\message.php on line 27

Notice: Undefined index: Message in C:\xampp\htdocs\BMNetwork\message.php on line 28
 
Thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 Kumi Festus · October 8, 2014
I still got errors based on your argument.
I finally had it done by defining them separately. Nevertheless your advice gave me more insight into that. This is how I did it.
<?php
if(isset($_POST["FullName"]) && !empty($_POST["FullName"])){
$name = mysql_real_escape_string($_POST["FullName"]);
}

if(isset($_POST["PhoneNumber"]) && !empty($_POST["PhoneNumber"])){
$phone = mysql_real_escape_string($_POST["PhoneNumber"]);
}

if(Isset($_POST["Gender"]) && !empty($_POST["Gender"])){
$gender = mysql_real_escape_string($_POST["Gender"]);
}

if(isset($_POST["Message"]) && !empty($_POST["Message"])){
$message = mysql_real_escape_string($_POST["Message"]);
}
 

if(!mysql_connect("localhost","root","")){
die("could not connect to database".mysql_error());
}else if(!mysql_select_db("data1")){
die("Database not selected".mysql_error());
}else if(!mysql_query("INSERT INTO users1
(FullName,PhoneNumber,Gender,Message)
 VALUES('$name','$phone','$gender','$message')")){
die("Could Not Save data".mysql_error());
}
 ?>
  • 1

SQL & Databases

129,816 followers
About

Everything SQL and Databases related in here!

Links
Moderators
Bucky Roberts Administrator