I've built a very simple html form with only one input box. I'm trying to get the value entered into my database.
It only seems to be half working as when I submit the form, I do get an entry and an ID number (which is on auto-incriment) however the "input1 field remains empty.
It's on VARCHAR and NULL. I've changed it to INT but does the same thing.
I'm really not sure whether the problem lies with MySQL or PHP.
I'm a little prone to typos in my code, but for the life of me I can't find one here.
Does anyone have a solution?
Regards
PHP PAGE
<?php
define ('DB_NAME', 'xxxx');
define ('DB_USER', 'xxxx');
define ('DB_PASSWORD', 'xxxx');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Cannae connect tay the server, sorry pal: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die ('Ya just pure cannae connect tay the big bad mental database min: ' . DB_NAME . ': ' . mysql_error());
}
echo 'Connected successfully';
$value = $_POST['input1'];
$sql = "INSERT INTO demo (input1) VALUES ('$value')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close ();
?>
FORM PAGE
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>Test form</h2>
<p>This form will send data to the MySQL database.</p>
</br>
<form action="testsend.php" method="post" />
<p>Input 1: <input type="text" name"input1" /></p>
<input type="submit" value="Submit" />
</form>
</body>
</html>
imput1only holds an empty string in the database?empty($value)and insert only if it is not empty