I have a PHP script that inserts rows into a table based on selected rows from a MySQL array.
the code to insert the rows into the new table is:
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer)
select `case no`,`gross mass`,`case status`, customer from
availablestock where `case no` = '$val'";
I want to assign all the inserted rows the same ID so that multiple stock items share the same LoadID.
How can I modify my code to do this so all the inserted records share the same ID and the ID is unique to the load.
I thought I could use the code below to get the max id and increment it by one
SELECT max(loadid)+1 from loaddetails
How can I acheive this? I realise my PHP code is not perfect but it is functional, I just need to add the functionality to allow for the rows to be inserted with a common ID to produce a result as below:

Thanks in advance for the assistance.
Regards,
Ryan Smith
Complete code is:
<?php
mysql_connect("localhost", "user", "password")or die("cannot connect");
mysql_select_db("databasename")or die("cannot select DB");
$sql="SELECT `case no`,`customer`,`gross mass`, `case status` from availablestock where transporttypename= 'localpmb'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table border=1>
<tr>
<td>
<form name="form1" method="post">
<table>
<tr>
<td>#</td>
<td>Case Number</td>
<td>Customer</td>
<td>Weight</td>
<td>Status</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><input type="checkbox" name=check[] value="<?php echo $rows['case no']; ?>"></td>
<td><?php echo $rows['case no']; ?></td>
<td><?php echo $rows['customer']; ?></td>
<td><?php echo $rows['gross mass']; ?></td>
<td><?php echo $rows['case status']; ?></td>
</tr>
<?php
}
?>
<tr>
<td><input name="planlocalpmb" type="submit" id="planlocalpmb" value="planlocalpmb"></td>
</tr>
<?php
$check=$_POST['check'];
if($_REQUEST['planlocalpmb']=='planlocalpmb'){
{
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer) select `case no`,`gross mass`,`case status`, customer from availablestock where `case no` = '$val'";
foreach($check as $key=>$value)
{
$sql="insert into loaddetails (CaseNo,GrossMass,CaseStatus,Customer) select `case no`,`gross mass`,`case status`, customer from availablestock where `case no` = '$value'";
$final=mysql_query($sql);
if($final)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=php.php\">";
} }
}
}
// Check if delete button active, start this
// if successful redirect to php.php
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
Make sure LoadID has an index!
You may need to lock the table first. I’m not sure.
I didn’t check the rest of your code, but I do notice you have an SQL Injection vulnerability there.