I’m attempting to use a form post to add rows to a mySQL table. Each row has a primary I’m calling quoteID. When a new form is submitted, it should add itself as a row in the table, with a quoteID of one greater than the previous quoteID. It current looks something like this:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
include 'verify.php';
$con = mysql_connect("localhost","user","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("internal", $con);
$previousOrderID = mysql_query("SELECT * FROM sourcingQuote ORDER BY quoteID DESC LIMIT 1");
$newOrderID = $previousOrderID + 1;
mysql_close($con);
?>
At the moment there are 4 rows in this table, with quoteID’s of 1,2,3 and 4. The odd thing is, if I attempt:
<? echo $previousOrderID; ?><br>
<? echo $newOrderID; ?><br>
The output result is:
Resource id #3
4
Regardless of how many rows are in the table, $previousOrderID is fixed to 3. How can I correct this? More so, it’s correct when I do addition to it, but why does it output ‘Resource id #3’ in the first place?
you can do this by choosing the auto increment in phpmyadmin
or by sql example the table name is demo and the colon is demo whit the auto increment and its promary key