PHP code isn´t right?
Posted: Mon Aug 29, 2011 6:44 pm
I want to see the latest results if I fill in my html form values for serial no, description, price and quantity, but it doesn´t work! Why?
<html>
<body>
<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$serial_no = $_POST["serial_no"];
$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];
mysql_select_db("eduardli_company", $con) or die(mysql_error());
mysql_query ("INSERT INTO Products (serial_no, description, price, quantity)
VALUES ('$serial_no', '$description', '$price', '$quantity')") or die(mysql_error());
$latest="select * from Products order by serial_no desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{
echo $row['serial_no'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>
<html>
<body>
<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$serial_no = $_POST["serial_no"];
$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];
mysql_select_db("eduardli_company", $con) or die(mysql_error());
mysql_query ("INSERT INTO Products (serial_no, description, price, quantity)
VALUES ('$serial_no', '$description', '$price', '$quantity')") or die(mysql_error());
$latest="select * from Products order by serial_no desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{
echo $row['serial_no'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>