I'm using a book to learn some PHP and MySQL and I'm trying to introduce things from an HTML form to a mysql DB and I don't really get what is happening.
HTML
<html>
<head>
<title>Joy of PHP</title>
</head>
<body>
<h1>Sam's Used Cars
</h1>
<form action="SubmitCarReader.php" method="post">
VIN: <input name="VIN" type="text" /><br />
<br />
Make: <input name="Make" type="text" /><br />
<br />
Model: <input name="Model" type="text" /><br />
<br />
Price: <input name="Asking_Price" type="text" /><br />
<br />
<input name="Submit1" type="submit" value="submit" /><br />
</form>
</body>
</html>
PHP
<html>
<head>
<title>Car saved</title>
</head>
<?php
$VIN = $_POST['VIN'];
$Make = $_POST['Make'];
$Model = $_POST['Model'];
$Price = $_POST['Asking_Price'];
$query = "INSERT INTO Masini_table
(VIN, Make, Model,Asking_Price)
VALUES(
'$VIN',
'$Make',
'$Model',
$Price
)";
echo($query);
$mysqli = new mysqli('localhost', 'root', '', 'masini');
if(mysqli_connect_errno()) {
printf("connect failed", mysqli_connect_error());
die();
}
echo("connected <br>");
$mysqli->select_db("masini");
echo("selected <br>");
if($result = $mysqli->query($query))
{
echo("introduced $Make $Model <br>");
}
else
{
echo("did not introduce $VIN <br>");
}
$mysqli->close();
?>
</body>
</html>
Errors:
Notice: Undefined index: VIN in C:\xampp\htdocs\SubmitCarReader.php on line 7
Notice: Undefined index: Make in C:\xampp\htdocs\SubmitCarReader.php on line 8
Notice: Undefined index: Model in C:\xampp\htdocs\SubmitCarReader.php on line 9
Notice: Undefined index: Asking_Price in C:\xampp\htdocs\SubmitCarReader.php on line 10
INSERT INTO Masini_table (VIN, Make, Model,Asking_Price) VALUES( '', '', '', )connected
I also find odd introducing $Price in the query without the '' like '$VIN' by example but I tried it both ways and it still does not work.
I'm also a beginner in PHP and MySQL so if I'm missing something important it would be really nice for you to explain it to me. Thanks.