...

View Full Version : Help with $_POST giving wrong value



swilkins
10-26-2009, 07:51 PM
I have created a page that asks for the user to choose a PO Number from a list - populated from a mysql database. After the PO Number is selected the page redisplays with information from that PO allowing the user to enter quantites shipped for each line on the PO.

The page (and all others) works fine from my laptop (localhost/using Apache/Windows) but when I upload it to my customers server (Linux/also using Apache) the value is returned wrong.

EX: They choose PO #267728 (shows fine in the drop down list and also when viewing source from the generated webpage the value options look correct) When the page refreshes and shows me the selected PO - I see: 267728ponbr=267728

I am sure that I have some missing punctuation or something in my code, but I have been looking for two days and can't find it. HELP!!!

Thanks in advance for any advise.


<?php
// This page allows the vendor to create a Packing List

// error_reporting(0); // Turns off all errors.

$page_title='Packing List Entry';
require_once ('./includes/mysql_connectpw.php'); // Connect to the db.

$ponbrfilter = '';
$plno = '';
$x = 1;
$fcs = "N";

if (isset($_COOKIE['ponbr']))
{
$ponbrfilter = $_COOKIE['ponbr'];
setcookie('[ponbr', $ponbrfilter);
}

if(isset($_POST['ponbr']))
{
$ponbrfilter = $_POST['ponbr'];
setcookie ('ponbr', $ponbrfilter);
}

if (isset($_COOKIE['plnbr']))
{
$plno = $_COOKIE['plnbr'];
setcookie ('plnbr', $_COOKIE['plnbr'], time() + 1800);
}

if(isset($_POST['oplnbr']))
{
if ($_POST['oplnbr'] == 'Choose Packing List')
{
}
else
{
setcookie ('plnbr', $_POST['oplnbr'], time() + 1800);
$plno = $_POST['oplnbr'];
}
}
if(isset($_POST['nplnbr']))
{
if ($_POST['nplnbr'] == 'Enter Packing List Number')
{
}
else
{
setcookie ('plnbr', $_POST['nplnbr'], time() + 1800);
$plno = $_POST['nplnbr'];
}
}
if ($plno == 'Enter Packing List Number' and $plno == 'Choose Packing List')
{
// Redirect the user to the vendor.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') )
{
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/popkglistnbr.php';
header("Location: $url");
exit(); // Quit the script.
}

$errors = array(); // Initialize error array.
if (isset($_COOKIE['user_id']))
{
/* Retrieve the user_id and vend_name for current user. */
$id = $_COOKIE['sman_id'];
$vn = $_COOKIE['last_name'];
$pt = $_COOKIE['pw_type'];

setcookie ('user_id', $_COOKIE['user_id']);
setcookie ('last_name', $vn);
setcookie ('sman_id', $id);
setcookie ('pw_type', $pt);

include ('./includes/vendheader.html');

echo "<DIV CLASS='noprint'>";
echo "<FORM ACTION='popkglist.php' name='sel' method='post'><P ALIGN='center'><FONT FACE='san-serif, tahoma, arial, helvetica'><B><BIG><big>$vn</big></big></b></font><br><br>";
echo "<FONT FACE='san-serif, tahoma, arial, helvetica'><BIG><b>Packing List Number:</b> &nbsp;&nbsp;</font><font FACE='san-serif, tahoma, arial, helvetica' color='red'><big>$plno</big></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT FACE='san-serif, tahoma, arial, helvetica'><b>PO Number: &nbsp;&nbsp;</font>";
echo "<SELECT NAME='ponbr' SIZE='1' onChange='document.sel.submit()'><OPTION VALUE='none'>Please Select PO";
$query = "SELECT distinct podnbr from podetail WHERE podvendno = '$id' and podtype != 'C' ORDER BY podnbr";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<OPTION VALUE="'.$row['podnbr'].'"';
if ($row['povendnbr'] != $ponbrfilter)
{
echo '>'.$row['podnbr'].'';
}
else
{
echo ' SELECTED>'.$row['povendnbr'].'';
}
}

$pnr = $row['podnbr'];
$query1 = "select plnbr from pldetail where plnbr = '$plno' and plponbr = $pnr";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1, MYSQL_ASSOC);
if ($row1)
{
echo ' * ';
}

echo "</SELECT></form><form action='plcomplete.php' name='plcomp' method='post'><input type='submit' value='Review and Print Packing List'><input type='hidden' name='pklstno' value='$plno' /></form></p>";

echo "<form action='popkglist.php' name='pkupd' method='post'>";
if ($ponbrfilter != '' and $ponbrfilter != 'none')
{
$query = "SELECT * from pohead WHERE ponbr=$ponbrfilter";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);

// Create the table.
echo '<TABLE ALIGN="center" WIDTH=100% CLASS="ftsz">';
echo '<TR><TD ALIGN="right"><B>PO Number:&nbsp;&nbsp;&nbsp;&nbsp;</B></TD><TD ALIGN="left"><B>'.$ponbrfilter.'</B></TD><TD ALIGN="right"><B>PO Date:&nbsp;&nbsp;&nbsp;&nbsp;</B></TD><TD ALIGN="left"><B>'.$row['podate'].'</B></TD><TD ALIGN="right"><B>Exp. Ship Date:&nbsp;&nbsp;&nbsp;&nbsp;</B></TD><TD ALIGN="left"><B>'.$row['podateship'].'</B></TD></TR>';
echo '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
echo '<TR><TD ALIGN="left" COLSPAN="6"><B>Special Instructions:</B><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>'.$row['pospecialinstr1'].'</B><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>'.$row['pospecialinstr2'].'</B><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>'.$row['pospecialinstr3'].'</B><BR></TD></TR></TABLE>';

echo '<TABLE ALIGN="center" WIDTH=100% CLASS="fts" BORDER="2" BORDERCOLOR="black">';
echo '<TR><TD ALIGN="center"><BIG><B>Item #</B></BIG></TD><TD ALIGN="center"><BIG><B>Item Description</B></BIG></TD><TD ALIGN="center"><BIG><B>Orig Order Qty</B></BIG></TD><TD ALIGN="center"><BIG><B>Bal on Ord</B></BIG></TD><td align="center"><big><b>On Pkg Lists</b></big></td><td align="center"><big><b>Qty Remaining</b></big></td><td align="center"><b><big>Qty to Ship</big></b></td></TR>';
$query2 = "SELECT * from podetail WHERE podnbr=$ponbrfilter ORDER BY podcollectdesc, podline";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
{
if ($row2['podtype'] == "C")
{
echo '<TR><TD ALIGN="left"><BIG><B>&nbsp;</B></BIG></TD><TD ALIGN="left"><BIG><B>'.$row2['poddesc'].'</B></BIG></TD><TD STYLE="text-align: right"><BIG><B>&nbsp;</B></BIG></TD><TD STYLE="text-align: right"><BIG><B>&nbsp;</B></BIG></TD><td>&nbsp;</td></TR>';
}
if ($row2['podeabal'] == 0.00)
{
}
else
{
$ord = $row2['podeaord'];
$ord = number_format($ord, 0);
$bal = $row2['podeabal'];
$bal = number_format($bal, 0);

echo '<TR><TD ALIGN="left"><BIG><B>'.$row2['poditem'].'</B></BIG></TD><TD ALIGN="left"><BIG><B>'.$row2['poddesc'].'</B></BIG></TD><TD STYLE="text-align: right"><BIG><B>'.$ord.'</B></BIG></TD><TD STYLE="text-align: right"><BIG><B>'.$bal.'</B></BIG></TD>';

$qtyid = 'qty'.$x;
$x = $x + 1;
$onpl = '0.00';

$plky = $plno;
$plky .= $ponbrfilter;
$plky .= $row2['podline'];
$pll = $row2['podline'];

$onpl = 0.00;
$query5 = "select * from pldetail where plponbr = $ponbrfilter and plpoline = $pll and plnbr != '$plno'";
$result5 = mysql_query($query5);
while ($row5 = mysql_fetch_array($result5, MYSQL_ASSOC))
{
$oplq = $row5['pltoship'];
$onpl = $onpl + $row5['pltoship'];
}
$baltoship = $row2['podeabal'] - $onpl;
if ($baltoship < 0.00)
{
$baltoship = 0.00;
}
$query3 = "select * from pldetail where plkey = '$plky'";
$result3 = mysql_query($query3);
$row3 = mysql_fetch_array($result3, MYSQL_ASSOC);
$qtyonord = $row3['pltoship'];
$qty00 = $_POST[$qtyid];
$qtymax = $baltoship * 1.05;
if ($row3)
{
if ($qty00 != '')
{
if ($qty00 > $qtymax)
{
$query4 = "delete from pldetail where plkey = '$plky'";
$result4 = mysql_query($query4);
$qtyonord = "INVALID";
}
else
{
$plsmship = (($row2['podsmbal'] / $row2['podeabal']) * $qty00);
$query4 = "update pldetail set pltoship=$qty00, plsmtoship=$plsmship where plkey = '$plky'";
$result4 = mysql_query($query4);
$qtyonord = $qty00;
}
}
}
else
{
if ($qty00 != '' and $qty00 != '0.00')
{
if ($qty00 > $qtymax)
{
$qtyonord = "INVALID";
}
else
{
$l = $row2['podline'];
$itm = $row2['poditem'];
$itd = $row2['poddesc'];
$cl = $row2['podcollect'];
$cld = $row2['podcollectdesc'];
$plsmship = (($row2['podsmbal'] / $row2['podeabal']) * $qty00);
$query4 = "insert into pldetail values ('$plky','$plno',$ponbrfilter,$l,'$id','','$itm','$itd','$cl','$cld',$qty00,'N',$plsmship)";
$result4 = mysql_query($query4);
$qtyonord = $qty00;
}
}
}

$baltoship = number_format($baltoship, 0);
$onpl = number_format($onpl, 0);
echo "<td style='text-align: right'><big><b>$onpl</b></big></td>";
echo "<td style='text-align: right'><big><b>$baltoship</b></big></td>";
if ($qtyonord == 'INVALID')
{
$qtyonord = 'MAX QTY '.$qtymax;
$bgclr = "red";
}
else if ($qtyonord == '0.00' or $qtyonord == '')
{
$qtyonord = '';
$bgclr = "#eeeced";
}
else
{
$qtyonord = number_format($qtyonord, 0);
$bgclr = "#eeeced";
}

echo "<td style='text-align: center' bgcolor=$bgclr><input type='text' style='text-align: right' id=$qtyid name=$qtyid size='15' value='$qtyonord' onChange='document.pkupd.submit()'></TR>";
}
}

echo '</TABLE></form>';
}
else
{
echo "&nbsp;";
}

include('./includes/footer.html');
}
?>

tomws
10-26-2009, 08:12 PM
I see one concatenation that you might want to look more closely at. Not sure if it's the root problem, but your example looks like a concat issue. Including a line before and after to help you locate it:

$plky = $plno;
$plky .= $ponbrfilter;
$plky .= $row2['podline'];

Also noticed a logic problem while glancing through:

if ($plno == 'Enter Packing List Number' and $plno == 'Choose Packing List')

swilkins
10-26-2009, 08:35 PM
Thanks I hadn't noticed the logic error - I will fix it.

The concat portion that you pointed out is a separate area, I am using a concatenated value for my database key - that is not used in this selection.

I will look again for stray .= but I have set a variable = $_POST['ponbr'] at the beginning of the file and displayed it and it has the extra data in it, also, I can't find a line that is ponbr= in the code anywhere.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum