I'm trying to connect my html form with MySQL database. So that what ever value the user inserts in the form our submitted to MySQL database . I have tried the following code but it is showing the following error on execution
'Undefined index: name in line 20' and 'Undefined index:address in line 21
Here is my html code
<!DOCTYPE html>
<html>
<body>
<form action="demo.php" method="post">
<p>Name: <input type="text" name="name"></p>
<p>Address: <input type="text" name="address"></p>
<input type="submit" value="Submit">
</form>
</body>
</html>
and here is my php code
<?php
define('DB_NAME', 'database');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost:3306');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$name = $_POST['name'];
$address = $_POST['address'];
$sql = "INSERT INTO table (name, address) VALUES ('$name', '$address')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close();
?>