<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<form name="entry" method='post' action="">
<label>NAME </label>
<input type="text"  /></br></br>
<input type="text" /></br></br>
<input type="submit"/>

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";

// Create connection
$conn = mysql_connect($servername, $username, $password);
$db = mysql_select_db("demo");

// Check connection
if (! $con) {
    die("Connection failed: " . mysql_error());
mysql_select_db("demo", $con) or die(mysql_error());
  if ($_POST)

$sql = "INSERT INTO demo(name, mobile)VALUES('$name','$mobile')";

if (!mysql_query($sql,$con))
    die('Error: ' .mysql_error());
echo "1 record added";

echo "Connecter succesfully";


Member Avatar

1) Please use PDO/mysqli as mysql_* functions are deprecated
2) The connection object is $conn and you keep referring to it as $con
3) You've messed up the conditionals - if post vars are not there, then line 46 onwards will still run.
4) Perhaps using HTML5 DTD would be better than XHTML?

This code looks 10 years old. Needs updating.