I'm a newbie to php I'm trying to write an application where a user selects multiple orders via a check box and all of the orders selected get written to a detail file. The next display lists a table of all the orders selected so the user can prioritize them. I also have a header screen program where the user enters the date, type, and manpower and writes that info to the header file. That write is being done in the beginning of this program. The problem is when I select the orders I am getting an error at the beginning of the code and when I echo the variables $date and $type are getting the value of ARRAY and the program is giving me an error on the SQL. I either need a way to skip over the top selection code or is there a way I can pass the array fields of the selected items to a third program that does the updates and displays the third screen. Here is the code. I took a PHP class about 4 years ago and haven't done much since so I'm at a loss here. If you can help me figure out how to do this I would appreciate it.
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
// Program name---->>> shipestimate.php
// This program is used to display orders ready for shipping.
// Author name----->>> Mary Beth Hamel
// Date written---->>> 05/28/14
session_start(); // start the session
ini_set('max_execution_time', 0);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="css/Luster1.css" rel="stylesheet" type="text/css" />
<link href="css/header.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/footer.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>Orders On the Dock</title>
</head>
<?php
require_once ('C:/wamp/db/login.php');
// Try to connect to database
try
{
$db = new PDO($db_hostname, $db_user, $db_pass);
}
catch (PDOExcepton $e)
{
echo $e->getMessage();
exit();
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// check variables selected and insert data into header
if (isset($_POST['manpower']))
{
$manpower = $_POST['manpower'];
}
if (isset($_POST['type']))
{
$type = $_POST['type'];
}
if (isset($_POST['date']))
{
$date = $_POST['date'];
}
if (isset($_POST['date']))
{
echo "date is " . $date;
echo "type is " . $type;
// Insert data into header if does not already exist if it does exist update Manpower.
$selstring = "Select Count(*) From LPCUSTTST.OPPSHEHD where shehdat = $date and shehtyp = '$type'";
$s = $db->prepare("$selstring");
$s->execute();
if($Count == 0) {
$selstring = "INSERT INTO LPCUSTTST.OPPSHEHD(shehdat, shehtyp, shehmanp) VALUES($date,'$type','$manpower')";
$s = $db->prepare("$selstring");
$s->execute();
}
else
{
$selstring = "UPDATE LPCUSTTST.OPPSHEHD(shehmanp) Values('$manpower')";
$s = $db->prepare("$selstring");
$s->execute();
}
}
$DATE = $date;
$TYPE = $type;
?>
<body>
<h3>Orders On the Dock</h3>
<form name="OrderInquirySelectionForm" method="POST" action="ShipEstimate.php">
Position To :
<input name="Pmptname" type="text" value="<?php echo $Pmptname;?>">
<input name="BtnSubmit" type="submit" value="Submit">
<br/><br/>
Sequence By :
<input name="chck" type="radio" <?php if (isset($chck) && $chck=="O") echo "checked";?> value="O"> Order #
<input name="chck" type="radio" <?php if (isset($chck) && $chck=="A") echo "checked";?> value="A"> Customer
<input name="chck" type="radio" <?php if (isset($chck) && $chck=="S") echo "checked";?> value="S"> Ship Date
<br/><br/>
</form>
<form name="form1" method="post" target='_self'>
<table border="1">
<tr class="bar" bgcolor='#CC9933'>
<th width='50' align='center' bgcolor='#7F462C'>Select</th>
<th width='200' align='center' bgcolor='#7F462C'>Order #</th>
<th width='200' align='center' bgcolor='#7F462C'>BO #</th>
<th width='300' align='center' bgcolor='#7F462C'>Customer</th>
<th width='100' align='center' bgcolor='#7F462C'>Sch Ship Date</th>
<th width='100' align='center' bgcolor='#7F462C'>Ordered Cases</th>
<th width='100' align='center' bgcolor='#7F462C'>Picked Cases</th>
<th width='100' align='center' bgcolor='#7F462C'>Cases To Pick</th>
<th width='100' align='center' bgcolor='#7F462C'>Wrapped Cases</th>
<th width='100' align='center' bgcolor='#7F462C'>Total Pallets</th>
<th width='100' align='center' bgcolor='#7F462C'>Full Pallets</th>
<th width='100' align='center' bgcolor='#7F462C'>F.P. Percent</th>
<th width='100' align='center' bgcolor='#7F462C'>Total Weight</th>
</tr>
<?php
if (isset($_POST['BtnSubmit']))
{
if (empty($_POST['Pmptname']))
{
If ($_POST['chck'] == 'S')
{
$Pmptname = 0;
}
else
{
$Pmptname = "' '";
}
}
else
{
$Pmptname = $_POST['Pmptname'];
$Pmptname = "'$Pmptname'";
}
if (isset($_POST['chck']))
{
$chck = $_POST['chck'];
}
else
{
$chck = 'N';
}
}
else
{
$chck = 'N';
$Pmptname = "' '";
}
$selstring = "SELECT DISTINCT OHORD, OHBORD, OHSCUS, OHSAD1, OHPRDT, SHOCAS, SHSKID, SHEWGT, SHFSKD FROM OPDBFA.OPPOHD, LPCUST.OPPCOT, LPCUST.OPPSHOHD WHERE OHORD = SHORDN AND OHBORD = SHBORD AND OHTYPE = OTTYPE AND OTPKSH = '1' AND OHSTAT <> 'RFI' AND OHSTAT <> 'RFR' AND OHTYPE <> 'TFR' AND OHHOLD <> '1' AND OHLOC='001 ' AND OHCO=' 001' AND OHUHLD <> 'CANCL' AND OHBORD = '00' AND OHRLDT > 0";
If ($chck == 'O')
{
$selstring = "$selstring AND OHORD >= $Pmptname ORDER BY OHORD, OHBORD";
}
If ($chck == 'A')
{
$selstring = "$selstring AND OHSCUS >= $Pmptname ORDER BY OHSCUS, OHPRDT";
}
If ($chck == '
S')
{
$selstring = "$selstring AND OHPRDT >= $Pmptname ORDER BY OHPRDT, OHSAD1";
}
If ($chck == 'N')
{
$selstring = "$selstring AND OHSAD1 >= $Pmptname ORDER BY OHSAD1, OHPRDT";
}
$rowclass = 0;
$LINE = 0;
$s = $db->prepare("$selstring");
$s->execute();
while($r = $s->fetch(PDO::FETCH_ASSOC))
{
$total = $s->rowCount();
$OHORD = $r[OHORD];
$OHBORD = $r[OHBORD];
$OHSCUS = $r[OHSCUS];
$OHSAD1 = $r[OHSAD1];
$OHPRDT = $r[OHPRDT];
$SHOCAS = $r[SHOCAS];
$SHSKID = $r[SHSKID];
$SHEWGT = $r[SHEWGT];
$SHFSKD = $r[SHFSKD];
$CUST = $OHSCUS . '-' . $OHSAD1;
$OHPRMDY = substr($OHPRDT,4,2). '-' .substr($OHPRDT,6,2).'-'.substr($OHPRDT,0,4);
$SHEWGT = number_format($SHEWGT, 2);
IF ($SHSKID <= 0)
{
$FPPCT = 0;
}
else
{
$FPPCT = ($SHFSKD / $SHSKID);
$FPPCT = ($FPPCT * 100);
$FPPCT = number_format($FPPCT, 0);
}
$class = " 'altcol$rowclass' ";
?>
<tr class="<?php echo $class;?>">
<td class="text"><input name="checkbox[]" type="checkbox" id="checkbox" value =<?php echo $LINE;?>></td>
<td class="text"><input name ="ohord[]" type="text" readonly ="readonly" value = <?PHP echo $OHORD;?>></td>
<td class="text"><input name ="ohbord[]" type = "text" readonly ="readonly" value = <?PHP echo $OHBORD;?>></td>
<td class="text"><input name ="cust[]" type = "text" readonly ="readonly" value = <?PHP echo $CUST;?>></td>
<td class="text"><input name ="ohprmdy[]" type = "text" readonly="readonly" value = <?PHP echo $OHPRMDY;?>></td>
<td class="text"><input name ="shocas[]" type = "text" readonly="readonly" value = <?PHP echo $SHOCAS;?>></td>
<td class="text"><input name ="pkqty[]" type = "text" readonly="readonly" value = <?PHP echo $PKQTY;?>></td>
<td class="text"><input name ="lftpck[]" type = "text" readonly="readonly" value = <?PHP echo $LFTPCK;?>></td>
<td class="text"><input name ="wrpqty[]" type = "text" readonly="readonly" value = <?PHP echo $WRPQTY;?>></td>
<td class="text"><input name ="shskid[]" type = "text" readonly="readonly" value = <?PHP echo $SHSKID;?>></td>
<td class="text"><input name ="shfskd[]" type = "text" readonly="readonly" value = <?PHP echo $SHFSKD;?>></td>
<td class="text"><input name ="fppct[]" type = "text" readonly="readonly" value = <?PHP echo $FPPCT;?>></td>
<td class="text"><input name ="shewgt[]" type = "text" readonly="readonly" value = <?PHP echo $SHEWGT;?>></td>
<td class="text"><input name ="date[]" type="hidden" value<?php echo $DATE;?>></td>
<td class="text"><input name ="type[]" type="hidden" value<?php echo $TYPE;?>></td>
</tr>
<?php
$LINE++;
$rowclass = 1 - $rowclass;
}
?>
<tr>
<td><br/><input name="submit" type="submit" value="Submit"></td>
</tr>
</form>
</table>
<?php
if (is_array($_POST['checkbox'])) {
$ohord = $_POST['ohord'];
$ohbord = $_POST['ohbord'];
foreach($_POST['checkbox'] as $line_no){
$selstring = "INSERT INTO LPCUSTTST.OPPSHEDT(sheddat, shedtyp, shedord, shedbord) VALUES($DATE,'$TYPE', '$ohord[$line_no]','$ohbord[$line_no]')";
echo $selstring;
$s = $db->prepare("$selstring");
$s->execute();}
}
?>
<?php
//include("footer.php");
?>
</body>
</html>
Comment