I have two php files that are called form1.php, and demo12.php. This is the result of the form1.php file:
<form action="demo12.php" method="post" />
<p>Name <input type="text" name="input1" /></p>
<p>Age <input type="text" name="input2" /></p>
<input type="submit" value="Submit" />
</form>
Then the code of my demo12.php is:
<?php
define('DB_NAME', 'form1');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');
$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());
}
$value = $_POST['input1'];
$value2 = $_POST['input2'];
$sql = "INSERT INTO user_info (name, age) VALUES ('$value', '$value2')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM name") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
echo $row["name"];
}
?>
I am able to enter a name, age, then click the submit button, which brings the user to the demo12.php page and inserts the data into the MySQL database. The problem is, I want to retrieve and then display all from the name column onto the page. So I have a database named form1, them a table named user_info. In that the 3 columns I have are ID, name, and age. To display all from the name column I have this at the near-end of my script:
$result = mysql_query("SELECT * FROM name") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
echo $row["name"];
}
Then when the data is inserted, then when it is going to display the all of the names in the table it has an error:
Table 'form1.name' doesn't exist
But it has no errors when I take that code out. Why is it not working?
mysql_*extension is depreciated please learnPDOormysqli_*