Forum Moderators: coopster
Here is the script:
<?php
//get the variables from the other page
$id=$_POST['id_no'];
$sku=$_POST['sku'];
$description=$_POST['description'];
$order=($_POST['order_qty']);
$store=$_POST['store'];
$comment=$_POST['comment'];$ip=$REMOTE_ADDR;
//check if store is empty
if(empty($store)) {
die("Store is required. Please press the back button and enter in your store.");
}
//connect to the database
require('../inc/database_conn.php');
//$month=getdate(mon);
//$day=getdate(mday);
//$year=getdate(year);
//$today=$year . "-" . $month . "-" . $day
$today=date('Y-m-d');
// create the unique order number
$headerqry = "INSERT INTO misc_order_header (order_date, store, comment, ip) VALUES ('$today', '$store', '$comment', '$ip')";
mysql_query($headerqry, $conn) or die(mysql_error());
$order_no=mysql_insert_id();
foreach($order_qty as $id_no => $val) {
if($order_qty[$id_no] > 0) {
$detailqry = "INSERT INTO misc_order_detail (order_no, id_no, sku, order_qty, order_date, store) VALUES ('$order_no', '$id_no', '$sku', '".$order_qty[$id_no]."', '$today', '$store')";
mysql_query($detailqry, $conn) or die(mysql_error() . "<BR>" . $detailqry);
}
}
Thanks for any help you can offer me.
>> Invalid argument supplied for foreach()
normally means the first argument in the foreach construction is not an array.
i notice you put the var $_POST['order_qty'] into $order - so you should be looping through
foreach ($order as ...)
the reason why it worked on the osx machine is probably because register globals [es2.php.net] were turned on:
this means to your old environment (osx) $order_qty is the same as $_POST['order_qty'] - but on the new linux box you have to specifically access the $_POST value - because in all recent versions of php register globals [es2.php.net] is turned off by default.
further down your script you try to capture the $REMOTE_ADDR; this won't work either - you will need $_SERVER['REMOTE_ADDR'].
google for 'php register globals' or check the manual from the link above
hth
<edit misspelling>
I also noticed my $REMOTE_ADDR problem last night. After reviewing the PHP website I changed the line to
$ip = getenv(REMOTE_ADDR);
Will that do the same as
$ip = $_SERVER['REMOTE_ADDR'];
or should I use the Server method?
Thanks,
Jeff
On the other hand, the $_SERVER [php.net] variables are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others. That said, a large number of the $_SERVER variables are accounted for in the CGI 1.1 specification [hoohoo.ncsa.uiuc.edu], so you should be able to expect those.
HTTP_REFERER:
'HTTP_REFERER'The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
In looking over the list of $_SERVER vars, there are several that are provided by the user agent. So I could really only rely on the ones that are actually set by the server itself, like HTTP_HOST, DOCUMENT_ROOT, SERVER_NAME and such.