0
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

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





<?php
$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)
  {
      $name=$_POST['name'];
      $mobile=$_POST['mobile];

$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";

mysql_close($con);

?>
2
Contributors
1
Reply
13
Views
2 Years
Discussion Span
Last Post by diafol
0

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.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.