0

Why is the serial no always 0 while I put other numbers?


Php file:

<html>
<body>

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];

mysql_select_db("eduardli_company", $con) or die(mysql_error());


mysql_query ("INSERT INTO Products (description, price, quantity)
VALUES ('$description', '$price', '$quantity')") or die(mysql_error());

$latest="select * from Products order by serialno desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{
echo $row . " " . $row . " " . $row . " " . $row;
echo "<br />";
}

mysql_close($con);
?>

</body>
</html>


form.html:

<html>
<head>
<style type="text/css">

#desc
{
width:10%;
height:5%;
}
</style>
<title>POST</title>
</head>

<body>


<form action='insert.php' method="post">

Serialno.: <input type="text" name="serialno" id="serialno"><br />
Description: <input type="text" name="description" id="description"><br />
Price: <input type="text" name="price" id="price" /><br />
Quantity: <input type="text" name="quantity" id="quantity" />
<input type='submit' value='submit' />


</form>

</body>
</html>

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by almostbob
0

wrap your code in [code=language]codesample [/code] makes it easier to read, turns on code highlighting, sometimes the highlights can solve the problem, they show up mismatched braces miss-spelled codewords etc

your code wrapped in [code=php]

<?php
$con = mysql_connect("localhost","eduardli_user","-z.x,c");
if (!$con) { die('Could not connect: ' . mysql_error()); }
$description = $_POST["description"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];
mysql_select_db("eduardli_company", $con) or die(mysql_error());
mysql_query ("INSERT INTO Products (description, price, quantity) VALUES ('$description', '$price', '$quantity')")
 or die(mysql_error());
$latest="select * from Products order by serialno desc limit 0,1";
$result = mysql_query($latest,$con) or die(mysql_error());
$row = mysql_fetch_array($result);
{ echo $row['serialno.'] . " " . $row['description'] . " " . $row['price'] . " " . $row['quantity'];
echo "<br />";
}
mysql_close($con);
?>

assuming serialno is the autoincrement field
try

$latest="select * from Products order by serialno desc limit 1";

select the first 1 result,
the original code chooses the first result starting at record(0), which is always equal to record(0)

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.