I have this contact form that I am trying to get to input information from my website into the designated table in my database. Does anyone know what I need to get this code to run correctly? I can input information in the textfields on my website and hit submit, but for some reason, the first name, last name, email, etc does not show up in the database at all. When I click submit, my "thank you" message does show up. I will include what my contact form, php, and database look like, perhaps that will help.
Contact Form contactus.php
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Contact</title>
<style type = "text/css">
em { font-weight: bold;
color: black; }
p { font-size: 12pt;
font-family: times new roman, sans-serif; color: black; }
</style>
</head>
<body>
<?php include ('menu.html'); ?>
<? include ("form_process.php"); ?>
<br> Please fill out the form below with your contact information.<br>
<form action= "form_process.php" method= "post" name= "contact_form"><br>
<p>First Name:
<input name= "first_name" type= "text" id= "first_name"/>
</p><br>
<p>Last Name:
<input name= "last_name" type= "text" id= "last_name"/>
</p><br>
<p>Email:
<input name= "email" type= "text" id= "email"/>
</p><br>
<p>Phone:
<input name= "phone" type= "text" id= "phone"/>
</p><br>
<p>Result:
<div>
<select name= "result" id= "result">
<option value="">Choose</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
</div>
</p><br>
<p>Comments:
<textarea name= "comments" id= "comments" placeholder= "Comment here" cols="25", rows="3"></textarea>
</p><br>
<p>Thank you for visiting our site!</p><br>
<p>
<input type= "submit" name= "submit" id= "submit" value= "Submit" />
<input type= "reset" name= "Reset" id= "reset" value= "Reset" />
</p>
</form>
<div class="footer"><?php include('footer.html');?></div>
</body>
</html>
Database The name of my database is project The table that I wish for the information to be input is called contactform & it is currently empty except the variables I have created. Within the table of contactform I have the variables:
ID int(10) AUTO_INCREMENT
first_name varchar(60)
last_name varchar(60)
email varchar(60)
phone int(15)
result varchar(15)
comments varchar(255)
**UPDATE: When I change my php to this (I tried to follow @DaveCartwright suggestions):
<?php
$user = 'root';
$pass = '';
$db = 'project';
$db = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect to database");
/*I do not know what you mean by this: mysqli_real_escape_string($db, $escapeString);*/
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$result = $_POST['result'];
$comments = $_POST['comments'];
$first_name = mysql_real_escape_string($first_name);
$last_name = mysql_real_escape_string($last_name);
$email = mysql_real_escape_string($email);
$phone = mysql_real_escape_string($phone);
$result = mysql_real_escape_string($result);
$comments = mysql_real_escape_string($comments);
$query= "INSERT INTO `project`.`contactform` (`ID`,`first_name`, `last_name`,
`email`, `phone`, `result`, `comments`)
VALUES (NULL, '$first_name', '$last_name', '$email', '$phone', '$result', '$comments');";
mysqli_query($db, $query) or die(mysqli_error($db));
echo "<h2>Thanks, your information has been submitted!</h2>";
?>
I get several notices of undefined variables for escapeString (line 8), undefined index for: first_name (line 10), last_name (line 11), email (line 12), phone (line 13), result (line 14), comments (line 15). However, good news: when I look in my database table I do have some input there. The ID fills in correctly, then for the variable phone the only thing listed is 0 & all other variables are empty for each entry. This is at least some progress - I have not actually seen entries show up before now. How can I further fix this so that all the input will show up?