Hi there I am a beginner of PHP, I am attempting to design a website using php and phpmyadmin. This website is supposed to view all records from a database, delete and add records.The following code is for adding a new record, I have errors on line 16, 20, 30, 32, 34, 36 and 83.
Error Example: Notice: Undefined variable: error in C:\xampp\htdocs\New.php on line 16 the same applies to as mentioned previously, lines 20, 30, 32, 34, 36 and 83.
I have included the line numbers next to the lines of code with the errors (e.g.Line30)
What is causing these problems and what do I need to do to resolve them ???
<title>New Record
<?php
(Line16)if ($error != '');
{
(Line20)echo '<div style="padding: 4px; color: red">'.$error.'</div>';
}
?>
<div>
(Line30)ID: * <input type="int" name="ID"<?php echo $ID; ?> /><br>
(Line32)ProductName: * <input type="VARCHAR" name="ProductName"<?php echo $ProductName; ?> /><br>
(Line34)Price: * <input type="text" name="Price"<?php echo $Price; ?> /><br>
(Line36)Stock: * <input type="int" name="Stock"<?php echo $Stock; ?> /><br>
<p>* required</p>
</div>
<?php
$con = mysqli_connect("localhost","root","");
if (!$con)
{
mysqli_select_db("stationaryonlinecustomers", $con);
}
if (isset($_POST['submit']))
{
$ID = mysql_real_escape_string(htmlspecialchars($_POST['ID']));
$ProductName = mysql_real_escape_string(htmlspecialchars($_POST['ProductName']));
$Price = mysql_real_escape_string(htmlspecialchars($_POST['Price']));
$Stock = mysql_real_escape_string(htmlspecialchars($_POST['Stock']));
}
(Line 83)if ($ID == '' || $ProductName == '' || $Price == '' || $Stock =='')
{
$error = 'ERROR: Please fill in all required fields!';
}
else{
$u = mysql_query($con, "INSERT productorders SET ID='".$ID."', ProductName='".$ProductName."', Price='".$Price."', Stock='".$Stock."'");
header("location:View.php");
renderForm('','','');
}
?>
What I have tried:
PHP books, Online websites, youtube and consulting fellow colleagues.