assign common id to multiple rows inserted from mysql array

Hi,

I am developing and PHP MySQL application. I have a page which displays records from a MySQL query. each record has a corresponding check box. the user then checks the check boxes they require and clicks next. On clicking next I want the selected rows to be inserted into another table with a common ID.

The concept is similar to that of an order process. slect products and all the products are inserted into an orders table with a common order number.

I am a novice PHP and MySQL guy so I am aware that my code is not 100%. If you could assist in assigning one common ID that would be appreciated.

My Code is currently:


<?php mysql_connect("localhost", "username", "password")or die("cannot connect"); mysql_select_db("databasename")or die("cannot select DB"); $sql="SELECT `crtd dept`,`customer`,`case no`,`gross mass` from despgoods_alldetails where transporttypename= 'localpmb'"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?>
<?php while($rows=mysql_fetch_array($result)){ ?> <?php } ?>
                <tr>
                    <td colspan=3><input name="Next" type="submit" id="Next" value="Next"></td>
                </tr>
                <?php
                
                
                        
                        $check=$_POST['check'];
                        
                    if($_REQUEST['Next']=='Next'){

{
$sql=“INSERT INTO loaddetails (dispatcharea,Customer, casenumber, weight,LOCStatus)
SELECT crtd dept,Customer,case no,gross mass,‘in Load Creation’
FROM despgoods_alldetails WHERE Case No = ‘$val’”;

                        foreach($check as $key=>$value)
                        {
                        $sql="INSERT INTO loaddetails (dispatcharea,Customer, casenumber, weight,LOCStatus)
						SELECT `crtd dept`,Customer,`case no`,`gross mass`,'in Load Creation'
						FROM despgoods_alldetails WHERE `Case No` = '$value'";
                        $final=mysql_query($sql);
                        if($final)
                        {
                        echo "<meta http-equiv=\"refresh\" content=\"0;URL=planlocalpmbstep2.php\">";
                        }                                            } 
                            }
                            }
                // Check if delete button active, start this

// if successful redirect to php.php

mysql_close();
?>

# Dispatch Area Customer Case Number Weight
<?php echo $rows['crtd dept']; ?> <?php echo $rows['customer']; ?> <?php echo $rows['case no']; ?> <?php echo $rows['gross mass']; ?>

Thanks for the help,
Ryan

In this following:
[php]
$sql=“INSERT INTO loaddetails (dispatcharea,Customer, casenumber, weight,LOCStatus)
SELECT crtd dept,Customer,case no,gross mass,‘in Load Creation’
FROM despgoods_alldetails WHERE Case No = ‘$val’”;
[/php]

you use a variable named $val. Where is this variable coming from

Sponsor our Newsletter | Privacy Policy | Terms of Service