Click to See Complete Forum and Search --> : MySQL INSERT multiple entries with same form names


noboost4you
07-30-2008, 03:27 PM
Workers populate one specific table/database with product that is due in.

Once the product is received, I want the receiving department to go down the list, check the box under the Received column that populates with every entry, and hit the "Received" button at the button of the page. From that request, I want each row that was "checked" to be deleted from the first table/database and inserted into another table/database with one additional field that wasn't present in the first table/database (current date stamp).

I've been able to do check the boxes, receive, and have the rows deleted from the first table and inserted into the second table, but because I want to throw a date stamp on when the items were received, I'm at a standstill.

Here is the code I'm working with:

<?php


$con = mysql_connect("IP", "USER", "PASS");
if (!$con)
{
die('Could not connect: ' .mysql_error());
}

mysql_select_db("expedite", $con);

if ($_POST['archive'])

{

foreach($_POST['archive'] as $key => $RequestNum)

{

$archive=("INSERT INTO archive SELECT * FROM request WHERE RequestNum='".(int)$RequestNum."'") or die(mysql_error());

$del=("DELETE FROM request WHERE RequestNum='".(int)$RequestNum."'") or die(mysql_error());

mysql_query($archive);
mysql_query($del);

echo "<center><body bgcolor='#E1E1E1'><font face='arial'>";
echo "Record Added to Received Database";
echo "<META HTTP-EQUIV='Refresh' CONTENT='2; URL=result.php'>";

}

}
else

{

echo "<center><body bgcolor='#E1E1E1'><font face='arial'>";
echo "Please select at least one row to receive";
echo "<META HTTP-EQUIV='Refresh' CONTENT='2; URL=result.php'>";

}




mysql_close($con)
?>

How can I throw a date stamp into that equation?

Thanks

cridley
08-01-2008, 06:44 AM
Not sure I fully understand the question but say archive table's last column is a datetime column (which is not present in request table), you could just do :


"INSERT INTO archive SELECT *, NOW() FROM request WHERE RequestNum=$RequestNum"

noboost4you
08-01-2008, 06:55 AM
Correct, the datetime column is not present in the request table, but is a functional column in the archive table. Would the NOW() statement know to put it in the last column without directly telling it where to go?

cridley
08-01-2008, 06:58 AM
Because NOW() follows the * it will go at the end.
If it was the first column in the archive you would do SELECT NOW(),* FROM...
If it's in the middle (why?), you'd enumerate the columns SELECT Col1,Col2,NOW(),Col3,Col4 FROM....

noboost4you
08-01-2008, 06:59 AM
The column's name is 'DateReceived'

cridley
08-01-2008, 07:02 AM
The name is irrelevant, as long as the types are the same. I assume 'request' and 'archive' are identical except for the datereceived column, if that's the last column, my first answer should work.

cridley
08-01-2008, 07:04 AM
"INSERT INTO archive SELECT *, NOW() FROM request WHERE RequestNum=$RequestNum" Is directly telling it to put the current timestamp (NOW()) into the last column.

noboost4you
08-01-2008, 07:12 AM
I'll give it a shot here shortly. Thanks

noboost4you
08-01-2008, 07:13 AM
Ah, that worked, but, it's displaying the wrong timezone. Seems to be 2 hours behind.

noboost4you
08-01-2008, 07:29 AM
Problem solved:
DATE_ADD(NOW(), INTERVAL 2 HOUR) changes the time to EST.

Thanks again.

cridley
08-01-2008, 09:26 AM
NOW() will be server time. Sounds like if you're in EST, your server is located somewhere in MST? (I'm English, so just guessing as I'd normally just do everything in GMT)

noboost4you
08-01-2008, 10:29 AM
NOW() will be server time. Sounds like if you're in EST, your server is located somewhere in MST? (I'm English, so just guessing as I'd normally just do everything in GMT)

That's exactly it. Problem has been solved.

Thanks again