Sooo I've been working on a site for a friend of my dads so he can keep his business in check etc. I've been using the While Loop to print out a table of the 'Tasks' that can be inputted in to the site, however when I go to change the status of the task it's not doing so?
I'm sure that is the way I'm getting the ID for locating the record that needs to be updated, but I think I'm on the correct lines. So firstly, is there anything obvious other than my shoddy coding? Secondly, this there any better way of getting the ID or the reasoning for the lack of updating? Much Obliged!
HTML - The page
<table class="tasktable">
<tr>
<th style="text-align: center; width: 100px ">Job Number (ID)</th>
<th style="text-align: center; width: 100px">VRM</th>
<th style="text-align: center; width: 175px;">Date Arrived</th>
<th style="text-align: center;">Work</th>
<th style="text-align: center; width:200px;">Customer</th>
<th style="text-align: center; width: 250px;">Task Progress</th>
</tr>
<?php
include 'Login-System/db.php';
$query = 'SELECT * FROM outstanding WHERE taskprogress = "New" OR taskprogress = "In Progress" ORDER by id ASC';
$result = mysqli_query($conn, $query);
if($result):
if(mysqli_num_rows($result)>0):
while($tasks = mysqli_fetch_assoc($result)):
?>
<tr>
<td style="text-align: center;"><h4 name="jobnumberid"><?php echo $tasks['id'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['VRM'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['datearrived'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['work'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['customer'];?></h4></td>
<td>
<form action="SQL/taskchange.php" role="form" method="post" id="taskchange">
<select name="taskchanger" id="taskchanger" style="margin-top:6px;
width: 150px; float:left" class="form-control">
<option value="#"><?php echo $tasks['taskprogress'];?></option>
<?php
if ($tasks['taskprogress']== "New") {
echo '<option value="In Progress" class="form-control">In Progress</option>
<option value="Complete" class="form-control">Complete</option>';
} else { if ($tasks['taskprogress']== "In Progress") {
echo '<option value="New" class="form-control">New</option>
<option value="Complete" class="form-control">Complete</option>';
} else {
echo '<option value="New" class="form-control">New</option>
option value="In Progress" class="form-control">In Progress</option>';
}
}
?>
</select>
<button name="save" id="save" class="form-control" style="width: 75px; float:right;margin-top: 6px">Save</button>
</form>
</td>
</tr>
<?php
endwhile;
endif;
endif;
?>
</table>
PHP - Bit that inserts into the DB
<?php
if(isset($_POST['save'])){
include '../Login-System/db.php';
$id = mysqli_real_escape_string($conn, $_POST['jobnumberid']);
$newtask = mysqli_real_escape_string($conn, $_POST['taskchanger']);
$sql = "UPDATE outstanding SET taskprogress = '$newtask' WHERE id = '$id'";
mysqli_query($conn, $sql);
header("Location: ../outstanding.php?updated");
exit();
} else {
header("Location: ../outstanding.php?whoops");
exit();
}
Related
I'm trying to sort the data table via date picker range (server side) but can't get the date sorting part to work properly. Surely there are missing codes and other problems.
What am I missing?
<html lang="en">
<head>
<title>List</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<h1 align="center">List</h1>
</br>
</br>
</br>
<center> <p class="search_input">
<form method="post" action="#">
<input type="date" name="dateFrom"> <input type="date" name="dateTo">
<input type="submit" name="range" id="range" class="btn-info" />
</form>
</center>
<table align="center" cellspacing="0" cellpadding="0">
<thead class="fixedthead">
<th width="120px" style="text-align: center; color: navy">Name</th>
<th width="120px" style="text-align: center; color: navy">Description</th>
<th width="120px" style="text-align: center; color: navy">Date</th>
<th width="120px" style="text-align: center; color: navy">Open</th>
</thead>
<?php
//retrieve content via data picker range
$dateFrom = $_POST['dateFrom'];
$dateTo = $_POST['dateTo'];
$conn = mysqli_connect("localhost", "root", "", "order");
// get results from database
$result = mysqli_query($conn, "SELECT * FROM order.item WHERE date BETWEEN '$dateFrom' AND '$dateTo' ", MYSQLI_USE_RESULT)
or die(mysqli_error($conn));
while($row = mysqli_fetch_array( $result )) {
?>
<tbody>
<tr>
<td width="120px" style="text-align: center"><?php echo $row['name']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['description']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['date']; ?></td>
<td width="120px"><a href = "download.php?id=<?php echo $row['id']; ?>" style='text-decoration:none;'><button>View</button></a></td>
</tr>
</tbody>
</table><br><br><br>
<?php
}
?>
</body>
</html>
Any help is appreciated. Thanks guys!
Knowing nothing about your database...
$last_five_days = time() - 432000;
$sql = "SELECT * FROM order.item WHERE order.date > ".$last_five_days." ORDER BY order.date ASC";
If this answer doesn't help, then you need to provide us with more information about what you mean by "date picker range."
ORDER BY {column} ASC|DESC orders the rows by the indicated column. It defaults to ASC.
I'm using the WHERE clause to set up your last-five-days requirement. I'm assuming order.date (whatever you've actually named that) is storing a simple UNIX timestamp.
I have some code that at the moment, upon the page load up, doesn't display my table data, and when I type in a username into my text-box, it displays the data corresponding with the letters typed into the text-box to match the username characters.
I want it to automatically show my table data and make the username search optional, only display certain users when typed into the text-box.
My current code is below :
index.php
<form name="bulk_action_form" action="" method="POST"/>
<?php
if(isset($_POST['bulk_delete_submit'])) {
if(!empty($_POST['checked_id'])) {
$idArr = $_POST['checked_id'];
$username = $_SESSION['username'];
foreach($idArr as $id) {
mysqli_query($con, "DELETE FROM `users` WHERE `id` = '$id' AND `username` = '$username'");
echo "<p>".$id ."</p>";
}
$_SESSION['success_msg'] = 'Users have been deleted successfully.';
header("Location: admin_members.php");
} else {
echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one user to delete <i class="fa fa-spin fa-spinner"></i></div>';
}
}
?>
<div class="row">
<div class="card-box" style="border-radius: none; padding: 10px; border: 1px solid #E3E3E3; background: #EEEEEE;">
<button type="submit" class="btn btn-danger" name="bulk_delete_submit"><i class="fa fa-trash-o"></i></button>
</div>
</div>
<div id="result"></div>
</div>
</form>
(Ignore the , the result div is the main part, at listed for my JS code below).
JS in index.php
<script>
$(document).ready(function(){
$('#search_text').keyup(function(){
var txt = $(this).val();
if(txt != '') {
$.ajax({
url:"search.php",
method:"post",
data:{search:txt},
dataType:"text",
success:function(data)
{
$('#result').html(data);
}
});
} else {
$('#result').html('');
}
});
});
</script>
And then for my search.php
<?php
include_once('configuration/db.php');
?>
<div class="table-responsive">
<table class="table m-0">
<thead>
<tr class="gradeA">
<th><input type="checkbox" id="selectall"/></th>
<th style="text-align: center;">Username</th>
<th style="text-align: center;">Email</th>
<th style="text-align: center;">CPUKey</th>
<th style="text-align: center;">IP</th>
<th style="text-align: center;">Expirey</th>
<th style="text-align: center;">Enabled?</th>
<th style="text-align: center;">Profile Picture</th>
<th style="text-align: center;">User Level</th>
<th style="text-align: center;">Date/Time Registered</th>
<th style="text-align: center;">Account Credits</th>
<th style="text-align: center;">Free Gifted Credits</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_SESSION['username'];
$clients_result = mysqli_query($con, "SELECT id, username, email, cpukey, ip, time, enabled, profile_picture, userLevel, register_time, account_credits, free_gifted_credits FROM users WHERE username LIKE '%".$_POST["search"]."%'");
if(mysqli_num_rows($clients_result) > 0) {
while($payment_row = mysqli_fetch_array($clients_result)) {
echo '
<tr style="text-align: center; font-size: 12px;">
<td>
<input type="checkbox" name="checked_id[]" class="checkbox" value='.($payment_row['id']).'>
</td>
<td>
'.($payment_row['username']).'
</td>
<td>
'.($payment_row['email']).'
</td>
<td>
'.$payment_row['cpukey'].'
</td>
<td>
'.($payment_row['ip']).'
</td>
<td>
<b>'.$payment_row['time'].'</b>
</td>
<td>
'.($payment_row['enabled'] == 1 ? '<span class="label label-success">Yes</span>' : '<span class="label label-danger">No</span>').'
</td>
<td>
'.("<img src=".$payment_row['profile_picture']." alt='user-img' class='img-circle user-img' style='height: 20px; width: 20px;'>").'
</td>
<td>
'.userLevelValidation().'
</td>
<td>
'.$payment_row['register_time'].'
</td>
<td>
'.number_format($payment_row['account_credits'], 2, '.', '').'
</td>
<td>
'.number_format($payment_row['free_gifted_credits'], 2, '.', '').'
</td>
';
;
} }else{ ?> <tr><td colspan="12" style="text-align: center; padding: 30px; letter-spacing: 2px; color: red;"><i class="fa fa-spin fa-spinner"></i> <strong>Oh snap!</strong> No Purchase records found. <i class="fa fa-spin fa-spinner"></i></td></tr> <?php } ?>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$('#selectall').click(function() {
$(this.form.elements).filter(':checkbox').prop('checked', this.checked);
});
</script>
Any help would be much appreciated.
I'm trying to delete the selected rows from the list I have in mysql so I won't have to delete the rows in my table one by one. When I press delete, my page refreshes without any php error but I don't get the result desired either. here is what I have:
<?php $product_set = find_all_products(); ?>
<body>
<form action="manage_products.php" method="delete">
<div class="page">
<article>
<div id="page">
<?php echo message(); ?>
<h2>Manage Products</h2>
<table>
<tr>
<th style="text-align: left; width: 125px;">Location</th>
<th style="text-align: left; width: 250px;">URL to the Product</th>
<th style="text-align: left; width: 100px;">First Name</th>
<th style="text-align: left; width: 100px;">Last Name</th>
<th style="text-align: left; width: 100px;">Size</th>
<th style="text-align: left; width: 100px;">Status</th>
<th style="text-align: left; width: 100px;">Checked</th>
<th colspan="2" style="text-align: left;">Actions</th>
</tr>
<?php while($product = mysqli_fetch_assoc($product_set)){ ?>
<tr>
<td><?php echo htmlentities($product["location"]);?></td>
<td><?php echo htmlentities($product["productURL"]); ?></td>
<td><?php echo htmlentities($product["fname"]); ?></td>
<td><?php echo htmlentities($product["lname"]); ?></td>
<td><?php echo htmlentities($product["size"]); ?></td>
<td><?php echo htmlentities($product["status"]); ?></td>
<td><input name="checkbox" type="checkbox" id="checkbox[]" value="<?php echo $product['id']; ?>"></td>
<td>Edit Order</td>
<td>Delete Order</td>
</tr>
<?php } ?>
</table>
<?php
// Check if delete button active, start this
if(isset($_GET['delete']))
{
$checkbox = $_GET['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
$_SESSION["message"] = "Product deletion failed.";
redirect_to("created_products.php"); }
}
//mysqli_close($dbc);
?>
<br />
</div>
</div>
<br>
<input type="submit" name="submit" value="Delete" onclick="return val();"/>
</form>
<div class="clear-all"></div>
</article>
</div>
</body>
Also place all the code which is for deleting the rows in the starting of your file. Thank you #Traveller for this.
Instead of for loop, use WHERE IN
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
Replace that with
$ids = implode(",", $_POST['checkbox']);
$sql = "DELETE FROM product WHERE link_id in ($ids)";
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
I have to make one system where the system requires the process of adding new information. The process flow is the process of adding the new information carried by the employee where all the information, name and id of staff will insert in mysql database. When I tried the process of that, I found staff_id and staff_name was empty in database mysql.
This is my addStaff.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
$query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row["id"];
$staff_id=$row["staff_id"];
#mysql_free_result($result);
?>
<html>
<head>
<script>
function Validate()
{
if (document.addStaff.project_name.value == '')
{
alert('Please Insert Project Name!');
document.addStaff.project_name.focus();
return false;
}
if (document.addStaff.project_id.value == '')
{
alert('Please Insert Project ID !');
document.addStaff.project_id.focus();
return false;
}
if (document.addStaff.location.value == '')
{
alert('Please Insert Location!');
document.addStaff.location.focus();
return false;
}
if (document.addStaff.cost.value == '')
{
alert('Please Insert Cost!');
document.addStaff.cost.focus();
return false;
}
if (document.addStaff.pic.value == '')
{
alert('Please Insert Person In Charge!');
document.addStaff..pic.focus();
return false;
}
if (document.addStaff.detail.value == '')
{
alert('Please Insert Detail about the Project!');
document.addStaff.detail.focus();
return false;
}
}
</script>
</head>
<body>
<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="645" height="50" align="left" valign="middle"><strong>Welcome , You log in as <?php echo $_SESSION['SESS_STAFF_NAME'];?> </strong></td>
<td width="224" align="right" valign="middle"><strong>Log Out</strong></td>
</tr>
</table>
<?php
$idURL = $_GET['id'];
$query ="SELECT *
FROM staff s
JOIN inter1 i
ON (s.staff_name=i.staff_name)";
$result = mysql_query($query, $conn) or die("Could not execute query");
$row = mysql_fetch_array($result, MYSQL_BOTH); // using numeric index or array index
$staff_id = $row['staff_id'];
$project_name = $row['project_name'];
$location = $row['location'];
$detail = $row['detail'];
$pic = $row['pic'];
$staff_name = $row['staff_name'];
$project_id = $row['project_id'];
#mysql_free_result ($result);
?>
<center>
<form action="addStaff_process.php?id=<?php echo $staff_id; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onSubmit="return Validate()" >
<table border="1" width="70%" cellspacing="1" cellpadding="6" >
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT NAME :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_name" cols="50" rows="2" id="project_name"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >PROJECT ID:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="project_id" cols="50" rows="2" id="project_id"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" >LOCATION :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="location" cols="50" rows="2" id="location"></textarea></td>
</tr>
<tr align="center" bgcolor="">
<td align="left" style="padding:10px 10px 10px 10px;" > COST :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="cost" cols="50" rows="2" id="cost"></textarea></td>
</tr>
<tr align="center" bgcolor="" >
<td align="left" style="padding:10px 10px 10px 10px;" >PERSON IN CHARGE :</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="pic" cols="50" rows="3" id="pic"></textarea></td>
</tr>
<tr>
<td align="left" style="padding:10px 10px 10px 10px;">DETAIL ABOUT THE PROJECT:</td>
<td align="left" style="padding:10px 10px 10px 10px;" ><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
</table>
<p> </p>
<p>
<input class="form-submit" type="submit" name="submit" value="SUBMIT" onClick="return Validate()"/>
<input type = "reset" value = "RESET" />
</p>
</form>
</center>
</body>
</html>
And this is my addStaff_process.php
<?php
include("authenticationStaff.php");
include ("dbase.php");
extract( $_POST );
$idURL = $_GET['id'];
$project_name = $_POST['project_name'];
$location = $_POST['location'];
$cost= $_POST['cost'];
$pic= $_POST['pic'];
$detail = $_POST['detail'];
$project_id = $_POST['project_id'];
$staff_id = $_POST['staff_id'];
$staff_name = $_SESSION['SESS_STAFF_NAME'];
$result ="INSERT INTO inter1 (project_name,location,cost,pic,detail,project_id)
VALUES ('$project_name','$location','$cost','$pic','$detail','$project_id')";
$query = mysql_query ($result, $conn);
if(mysql_num_rows($query)){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
else{
$query1 = "UPDATE inter1 SET staff_name = '$staff_name',staff_id = '$staff_id' WHERE staff_name=$idURL";
$result1 = mysql_query ($query1, $conn);
if($result1){
echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
}
?>
Can someone see where I am going wrong?if you need any more info then please let me know. thanks.
You need to use session_start(); at the start of every page that accesses the session values.
DB MAP:
Carriers "table1": carriername, carrierid, ect... Post data
carrierinfo "table2": carriername, id, contact, ect... carrier list
I am using mysql_query from table2 for my carriername drop down. Using this I am able to post a carrier name to table1. I am trying to use the same drop down to post the related id from the selcected carriername. So in short I need to have one drop down that displays only the Carrier names but querys both carriername & id from table2. When the form is posted I need to post to the carriername & carrierid to table1. Below is the drop down I am using. Please let me know how I can connect the dots and add what is needed. If its possible.
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carrierid = mysql_real_escape_string($_POST['carrierid']);
$fromzip = mysql_real_escape_string($_POST['fromzip']);
$tozip = mysql_real_escape_string($_POST['tozip']);
$typeofequipment = mysql_real_escape_string($_POST['typeofequipment']);
$weight = mysql_real_escape_string($_POST['weight']);
$length = mysql_real_escape_string($_POST['length']);
$paymentamount = mysql_real_escape_string($_POST['paymentamount']);
$contactperson = mysql_real_escape_string($_POST['contactperson']);
$loadtype = mysql_real_escape_string($_POST['loadtype']);
$date = mysql_real_escape_string($_POST['date']);
$insert = "INSERT INTO Carriers (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW()) FROM carrierinfo WHERE id = '$carrierid'";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `Carriers` ORDER BY `date` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
?>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<input type="button" onclick="window.location.href='search.php';" value="Search Board" /><div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 10%;">Carrier:</td><td>
<?php
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$query=("SELECT * FROM carrierinfo");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="width: 10%;">Load Type:</td><td>
<select name="loadtype">
<option></option>
<option value="TL">Truck Load</option>
<option value="Partial">Partial</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Weight:</td><td> <input id="weight" name="weight" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Length:</td><td> <input id="length" name="length" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 10%;">Equip:</td><td>
<select name="typeofequipment">
<option></option>
<option value="AUTO">Auto Carrier</option>
<option value="DD">Double Drop</option>
<option value="F">Flatbed</option>
<option value="LB">Lowboy</option>
<option value="Rail">Rail</option>
<option value="Ref">Reefer</option>
<option value="RGN">Removable Goose Neck</option>
<option value="SD">Step Deck</option>
<option value="TANK">Tanker (Food, liquid, etc.)</option>
<option value="V">Van</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td> <input id="contactperson" name="contactperson" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50"
style="width: 100%;" type="text">
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"><input type="button" onclick="window.location.href='newcarrier.php';" value="Add Carrier" /></p>
</div>
</form>
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
Use a join:
SELECT t1.carrierid, t2.carriername, t2.id
FROM table1 t1 JOIN table2 t2 USING (carriername)
Joining tables should be one of the first things you learn when studying SQL.
UPDATE:
Never mind the above, your original query to populate the dropdown was correct. When you populate the select, you should do:
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
When posting the data, get rid of this line:
$carriername = mysql_real_escape_string($_POST['carriername']);
and change the insert query to:
$insert = "INSERT INTO Loads (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW())
FROM Carriers
WHERE id = '$carrierid'";
The change to the form makes it display the carrier name, but return the ID in the post data. Then the new INSERT query uses that ID to get the carrier name from table 2 and combine that with all the other post data when inserting into table 1.