Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6634265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:54:35+00:00 2026-05-25T22:54:35+00:00

I have a PHP script that inserts rows into a table based on selected

  • 0

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:

enter image description here

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:54:36+00:00Added an answer on May 25, 2026 at 10:54 pm
    INSERT INTO loaddetails (LoadID, CaseNo, GrossMass, CaseStatus, Customer)
    SELECT (SELECT MAX(loadid)+1 FROM loaddetails) LoadID, CaseNo, GrossMass, CaseStatus, Customer
    FROM availablestock WHERE CaseNo = '$val'
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that inserts values into mySQL table INSERT INTO stories
I have a PHP script that inserts data into a mysql database. The table
I have a PHP script that creates an entry into a mysql database. The
I have a php script that backup my table in .sql format and I
I am writing a PHP script that imports a csv and inserts into a
I have a script that, inserts into the database e.g. 20,000 users with email
I have php script that creates a temporary watermark image for users that are
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that initialises an image gallery. It loops through all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.