Hello everyone. I'm still new to PHP. What I would like to do is to place the value of the $truck inside the column Truck. I don't have any error messages whenever I run this page, so I don't really know what's wrong, and no values are placed inside the Truck table. The 'Location' belongs to the customer_information table, the rest from the customer_order table.

include ("database_connection.php");

$i = 0;
$result1 = mysql_query("SELECT * FROM `customer_information` INNER JOIN `customer_order`");
$count = mysql_num_rows($result1);
if ($count != 0)
	while($row1 = mysql_fetch_array($result1)){
		$order_no = $row1['Order_Number'];
		$cust_no = $row1['Customer_Number'];
		$receipt_no = $row1['Receipt_Number'];
		$date_ordered = $row1['Date_Ordered'];
		$exp_date = $row1['Expected_Date'];
		$location = $row1['Location'];
		$truck = $row1['Truck'];
	if ($location == 'place1' || 'place2')
		$truck = "truck1";
	} else if ($location == 'place3' || 'place4' || 'place5' )
			$truck = "truck2";
		}	else if ($location == 'place6' || 'place7' || 'place8')
				$truck = "truck3";
			}	else if ($location == 'place9')
					$truck = "truck4";
mysql_query("INSERT INTO `customer_order`(Truck) VALUES ('$truck')");


You do not check for mysql errors, so that could be a reason you don't get errors :)

Get used to, after all mysql_query(), add as shown here:

mysql_query(...) or die(mysql_error());

If mysql_query returns false, which it will if something goes wrong, it will stop execution, clear page and print mysql_error() which contains information about the latest error.

I hope this helps you!

The insert will create a new record in customerorders. Are you trying to do an update instead of an insert?

The other thing I see is the ( ) around truck in the insert:

mysql_query("INSERT INTO `customer_order`(Truck) VALUES ('$truck')");

I think what you would need is:

mysql_query("INSERT INTO `customer_order.Truck` VALUES ('$truck')");

But again that will create a new record instead of updating the original. Can you verify what you really want done....

@rch1231 : I want to INSERT

Thank you for the replies! I will try them all

Damn. Still not working

What I really want to do is to get the values from the customer_information table and the customer_order table, the Truck column is still empty by then. Then check the $location so the proper truck can be assigned, hence, the Truck column will have a value inside. Each order will be assigned a truck depending on the location.

Ok if I understand correctly you want to update the empty truck field in the customer_orders table with the correct truck based on the location of the order. If that is correct then you need to use update instead of insert. Insert is to create a completely new record for the order and update is used to change the value of an existing record even if the field in question is blank.

The statement:

mysql_query("INSERT INTO `customer_order`(Truck) VALUES ('$truck')");

Attempts to insert a new record in the Customer_Order table and only fill in the field Truck with a value and set it equal to $truck.

What you need is something like:

mysql_query("UPDATE customer_order set `Truck` = '$truck' where Order_Number = '$order_number' ");

Or something pretty close.
Does that make sense?

It worked! Thank you so much :D