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>
<title>Message Receiving Page</title>
<form action="message.php" method="post" enctype="multipart/form-data">
<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"/>
$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
  die("Data could not be save".mysql_error());
  echo "Data Saved To database";



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

Post a Reply


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.
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"]);

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
die("Could Not Save data".mysql_error());
  • 1

SQL & Databases


Everything SQL and Databases related in here!

Bucky Roberts Administrator