MySQL Database in Phpmyadmin won't update and shows no Error

Annoogy

New member
Hi
I am new to this but need urgent help for a project
I downloaded xamp and it is running
I created DB on PHPMyadmin and try to connect my php file to it from a html form
Here is code attached.
Wish some one help me with it
The file html file and php file are saved in xamp/htdocs
Database and output attached
Code:
<?php
// database connection code
if(isset($_POST['Submit']))
{
// $con = mysqli_connect('localhost', 'database_user', 'database_password','database');
$con = mysqli_connect('localhost', 'root', '','db_connect');

// get the post records

$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtRole = $_POST['txtRole'];
$txtArea = $_POST['txtArea'];
$txtRegion = $_POST['txtRegion'];

// database insert SQL code
$sql = "INSERT INTO `employees` (`id`, `name`, `email`, `role`, `solution_area` , `region`) VALUES ('0', '$txtName', '$txtEmail', '$txtRole', '$txtArea' ,'$txtRegion')";

// insert in database


$rs = mysqli_query($con, $sql);
echo $rs;
if($rs)
{
	echo "Contact Records Inserted";
  echo "New record has id: " . mysqli_insert_id($con);
}

else
{
	echo "Are you a genuine visitor?";

}
}
?>
My HTML
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form - PHP/MySQL Demo Code</title>
</head>

<body>
<fieldset>
<legend>Contact Form</legend>
<form name="frmContact" method="post" action="contact.php">
<p>
<label for="Name">Name </label>
<input type="text" name="txtName" id="txtName">
</p>
<p>
<label for="email">Email</label>
<input type="text" name="txtEmail" id="txtEmail">
</p>
<p>
<label for="role">Role</label>
<input type="text" name="txtRole" id="txtRole">
</p>
<p>
<label for="area">Solution-Area</label>
<textarea name="txtArea" id="txtArea"></textarea>
</p>
<p>
<label for="region">Region</label>
<textarea name="txtRegion" id="txtRegion"></textarea>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit">
</p>
</form>
</fieldset>
</body>
</html>
output
1.png
 

Attachments

  • 2.png
    2.png
    68.8 KB · Views: 1,116
On the line after 'are you a genuine visitor?', add:
Code:
echo mysqli_error($con);

This will print out the error you're experiencing.

As an aside, look into using prepared statements to make your code more secure.
 
Thanks so much. It helps me to solve the issue.
I am new to this what do you mean by using secure statment
Thanks a lot
 
Prepared statements are used for a few things, but the biggie for a new developer is that they allow you to use dynamic variables in your SQL safely. PHP Delusions and PHP The Right Way are good resources for learning about this and other parts of PHP development.
 
Back
Top