I've been searching and trying for the last few hours with no luck. Trying to do this. I have a web Purchase order system. It uses mysql which is obviously outdated. It's a simple code, I pull the ID of the last ponumber, +1 to it, and reinsert it. I also display the new number on the form. This allows my system to display the PO number before submitting, and ensures noone else gets the same number twice. Here is my old code. There is a connection section in the header, but it's the same as the conn below which is all i havent added.
$row = mysql_fetch_array($result);
$ID = $row['ID'] +1 ;
?>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("purchaseorder", $con);
$sql="INSERT INTO ponumber (ID)
VALUES
('$ID')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<form action="submit.php" method="post" name="form" id="form" accept- charset="utf-8">
<div class="form-all">
<ul class="form-section">
<li id="cid_1" class="form-input-wide">
<div class="form-header-group">
<h2 id="header_1" class="form-collapse-table">
Jillian Builders Purchase Order #:</h2><center><font size="9">
<?php echo $ID ?>
</h1></center></font></div>
This works just fine, other than an annoying sql is deprecated warning, which im trying to change. I cannot for the life of me figure out how to get the ID number using mysqli. I have tried numerous ways with fetch assoc, with array's, but for some reason I can't make it work. Im sure there is a better way to do this than what im doing. I'm open to suggestions. In the form. The employee needs to give the PO number to a vendor. Once he pushes submit on the form it submits the number in. So i need the number before he submits the data to the database so he can give it. Which is why i used +1. I get the old ID +1 to it to show the number in the FORM ONLY. It's not relevant to the actual DB. When he submits the PO it submits the number into it, and everything lines up. All i need to do it find a way to pull the ID off.
This is what i've tried so far to no avail
<?php
$data = mysqli_query($conn,"SELECT ID FROM ponumber ORDER BY ID DESC LIMIT 1");
while ($row = mysqli_fetch_assoc ($data)) {
extract ($row);
echo "
ID=$ID +1
";
}
Hope this helps clarify where i'm at Thanks in advance.