Thanks again, however no luck. At this point I am getting a warning and error
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\szabo\szabo-confirmation.php on line 93
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
:: Line 93 foreach($_POST['qnt'] AS $id => $qnt) {
I have added a prod_id column and <input>, works fine Each product has a unique id. Have varied your example numerous ways to use the prod_id instead of the qnt, at one point I was able to insert the last $_post.
I appreciate your time and don't really expect you to write my code for me, the why this is not working is baffling.
Below is the code for the two pages, maybe something will jump out.
Input page
PHP Code:
<?php session_start();?>
<?php require_once('Connections/szabo.php'); ?>
<?php require_once( "WA_SecurityAssist/Helper_PHP.php" ); ?>
<?php error_reporting(0);?>
<?php
if (!WA_Auth_RulePasses("Logged in to company")){
WA_Auth_RestrictAccess("company_LogIn.php");
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = post_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_szabo, $szabo);
$query_Recordset11 = "SELECT company.id, company.name FROM company WHERE id =$_SESSION[id]";
$Recordset11 = mysql_query($query_Recordset11, $szabo) or die(mysql_error());
$row_Recordset11 = mysql_fetch_assoc($Recordset11);
$totalRows_Recordset11 = mysql_num_rows($Recordset11);
$cust = $row_Recordset11 ['name'];
$cust=str_replace(' ', '', $cust);
$cust = strtolower($cust);
mysql_select_db($database_szabo, $szabo);
$query_Recordset22 = "SELECT * FROM $cust WHERE model IS NOT NULL";
$Recordset22 = mysql_query($query_Recordset22, $szabo) or die(mysql_error());
$row_Recordset22 = mysql_fetch_assoc($Recordset22);
$totalRows_Recordset22 = mysql_num_rows($Recordset22);
$query_Recordset222 = "SELECT * FROM $cust WHERE model IS NOT NULL";
$Recordset222 = mysql_query($query_Recordset222, $szabo) or die(mysql_error());
$row_Recordset222 = mysql_fetch_assoc($Recordset222);
$totalRows_Recordset222 = mysql_num_rows($Recordset222);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
margin:0px;
}
h1, h2, h3, h4,h5 {
margin:0px;
}
th {
width:80px;}
#orderform {
width:800px;
margin:0px auto;}
.center {
text-align:center;
}
</style>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<?php
$_SESSION['ptype']= $row_Recordset22['ptype'];
?>
<div id="orderform">
<h2><?php echo $row_Recordset11['name']; ?> Order Form</h2>
<table>
<th>Quantity</th><th>Product Id</th><th>Type</th><th>Manufacturer</th><th>Model</th> <th>Model Number</th> <th>Description</th><th>Price</th></tr>
<?php
do{
?>
<form action="szabo-confirmation.php" method="post" name="result" id="result">
<tr><td><select name ="qnt" id="qnt" ><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select></td>
<td><input type="text" id="prod_id" name="prod_id" size="4" readonly="readonly" value = "<?php echo $row_Recordset22[prod_id] ?>"></td>
<td><input type="text" id="ptype" name="ptype" size="10" readonly="readonly" value = "<?php echo $row_Recordset22[ptype] ?>"></td>
<td><input type="text" id="mfg" name ="mfg" size="10" readonly="readonly" value = "<?php echo $row_Recordset22[mfg] ?>"></td>
<td><input type="text" id="model" name="model" size="20" readonly="readonly" value = "<?php echo $row_Recordset22[model] ?>"></td>
<td><input type="text" id="model_num" name="model_num" size="20" readonly="readonly" value ="<?php echo $row_Recordset22[model_num] ?>"></td>
<td><input type="text" id="descrip" size="20" name="descrip" readonly="readonly" value ="<?php echo $row_Recordset22[descrip] ?>"></td>
<td><input type="text" id="msrp" name="msrp" size="10" readonly="readonly" value ="<?php echo $row_Recordset22[msrp] ?>"></td>
</tr>
<?php }
while($row_Recordset22 = mysql_fetch_assoc($Recordset22));
?>
</table>
<input name="submit" type="submit" name="temporsub" value="Submit for Confirmation" />
</form>
<?php
/*$_SESSION['$row22']=mysql_fetch_assoc($Recordset22);*/
?>
<?php
$myArr = array();
if(mysql_num_rows($Recordset222) > 0)//if it finds any row
{
while($result = mysql_fetch_array($Recordset222))
{
//adding data to the array
$myArr[] = $result->$Recordset222['qnt'];
}
}
/*print_r ($myArr);*/
?>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset11);
mysql_free_result($Recordset22);
?>
Result Page (confirmation)
PHP Code:
<?php session_start();?>
<?php require_once('Connections/szabo.php'); ?>
<?php error_reporting(0);?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {
margin:0px;
}
h1, h2, h3, h4,h5 {
margin:0px;
}
td {
text-align:center;}
.center {
text-align:center;
}
</style>
</head>
<body>
<?php
@$qnt = $_POST['qnt'];
@$qnta = array($_POST['qnt']);
array_push($qnta, "$qnt");
@$ptype = $_POST['ptype'];
@$mfg = $_POST['mfg'];
@$model = $_POST['model'];
@$model_num = $_POST['model_num'];
@$descrip = $_POST['descrip'];
@$msrp = $_POST['msrp'];
@$price = $qnt * $msrp;
@$po=$_POST['po'];
$prod_id=$_POST['prod_id'];
?>
<?php
mysql_select_db($database_szabo, $szabo);
$qry=mysql_query( "CREATE TABLE temporder LIKE orders ");
mysql_select_db($database_szabo, $szabo);
$query_Recordset1 = "SELECT company.name, company.store_num FROM company WHERE company.id =$_SESSION[id]";
$Recordset1 = mysql_query($query_Recordset1, $szabo) or die(mysql_error());
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
@$cust = "$row_Recordset1[name]";
@$store_num = "$row_Recordset1[store_num]";
mysql_select_db($database_szabo, $szabo);
///////////////////////////////////From Forum////////////////////////////////////////////
//Assumes $cust predefined (Session Value?)
$query_Recordset3 = "INSERT INTO temporder ( cust, qnt, prod_id) VALUES ";
foreach($_POST['qnt'] AS $id => $qnt) {
//Sanitize both $id and $qty here
$query_Recordset3 .= "('".$cust."','".$id."','".$prod_id."'),";
}
$query_Recordset3 = substr($query_Recordset3,0,-1); // get rid of trailing comma, since we cant use implode
$Recordset3 = mysql_query($query_Recordset3, $szabo) or die(mysql_error());
/////////////////////////////////////////////////////////////////////////////////////////////
$Recordset3 = mysql_query($query_Recordset3, $szabo) or die(mysql_error());
@$row_Recordset3 = mysql_fetch_array($Recordset3);
@$totalRows_Recordset3 = mysql_num_rows($Recordset3);
mysql_select_db($database_szabo, $szabo);
$query_Recordset2 = "SELECT * FROM temporder WHERE qnt >='1'";
$Recordset2 = mysql_query($query_Recordset2, $szabo) or die(mysql_error());
$row_Recordset2 = mysql_fetch_array($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
echo '<table cellspacing ="6" align="center">';
echo '<tr><th>'.'Quantity'.'</td>'. '<th>'.'Type'.'</td>'. '<th>'.'Manufacturer'.'</td>'. '<th>'.'Model'.'</td>'. '<th>'.'Model Number'.'</td>'. '<th>'.'Description'.'</td>'. '<th>'.'Price'.'</td></tr>';
do {
echo '<tr><td>'.'<input type="text" id="qnt" name="qnt" size="2" value = '."$row_Recordset2[qnt]".'>'. '</td>';
echo '<td>'."$row_Recordset2[ptype]".'</td>';
echo '<td>'."$row_Recordset2[mfg]".' </td>';
echo '<td>'."$row_Recordset2[model]".'</td>';
echo '<td>'."$row_Recordset2[model_num]".'</td>';
echo '<td>'."$row_Recordset2[descrip]".'</td>';
echo '<td>'."$row_Recordset2[price]".'</td>';
echo '</tr>';
$row_Recordset2 = mysql_fetch_array($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
}
while($row_Recordset2 = mysql_fetch_array($Recordset2));
echo '</table>';
?>
</body>
</html>
<?php
/*$row_Recordset1 = mysql_fetch_array($Recordset1);*/
?>
Thanks again
Gary
Bookmarks