PDA

View Full Version : PHP/Sql - Check a field exists before update.


HeadAche
05-02-2006, 02:39 PM
Hello... Can anyone help me on this. :shock: @ DJ...

On me auction frontend, I need to check that a client EXISTS in the clients table before I alow the UPDATE of the stock table. Anyone know in laymens terms how I can do this - is there maybe a way I can mod the Check Unique Server behavour to do this task ?!?!

Enter PRICE & Client ID into form fields > CHECK Client ID Exists in table CLIENTS > If client ID exists then UPDATE table STOCK with submitted values > If client doesnt exist then dont update and return error message under the UPDATE form "sorry, the client ID you entered does not exist in client records"...

:wink:

davidj
05-02-2006, 04:11 PM
just query the db with a select on the client id

then wrap the update statement in an IF below the SELECT

example..

select * from client where id = '%s', $clientid etc etc ...

IF ($totalrows_client > 0){ // < check that the above select found id

do update here; //< write your update statement here

}else{

display warning message here; // < do this if $totalrows_client = 0

}

write what you think it will be then i will check your syntax

HeadAche
05-03-2006, 10:21 AM
Like your style man... see what you think...


<?php $warningMessage =""; ?> //setting my warning message to nothing


IF ($totalrows_client > 0){
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "soldForm")) {
$updateSQL = sprintf("UPDATE stock SET SoldPrice=%s, AuctionDateSold=%s, Sold=%s, ClientID=%s WHERE Id=%s",
GetSQLValueString($_POST['SoldPrice'], "int"),
GetSQLValueString($_POST['AuctionDateSold'], "date"),
GetSQLValueString($_POST['Sold'], "text"),
GetSQLValueString($_POST['ClientID'], "text"),
GetSQLValueString($_POST['Id'], "int"));

mysql_select_db($database_auction, $auction);
$Result1 = mysql_query($updateSQL, $auction) or die(mysql_error());
}
}
else
}
$warningMessage = "The client does not exist, please try again." ; //else giving the warning message box the value of my message
}


<form>
the form stuff here and the warning message echo under
<?php echo $warningMessage; ?>
</form>

HeadAche
05-03-2006, 12:21 PM
ok, this is the code i have put in... The totalRows record is working fine (i have echo'd it onto the page)... but the record wont update with a bad CustomerID or one thats in the database... Oh, and I think the way I am sending the error message is abit cack (doesnt function)


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "soldForm")) {
IF ($totalRows_rst_customers > 0){
$updateSQL = sprintf("UPDATE stock SET SoldPrice=%s, AuctionDateSold=%s, Sold=%s, ClientID=%s WHERE Id=%s",
GetSQLValueString($_POST['SoldPrice'], "int"),
GetSQLValueString($_POST['AuctionDateSold'], "date"),
GetSQLValueString($_POST['Sold'], "text"),
GetSQLValueString($_POST['ClientID'], "text"),
GetSQLValueString($_POST['Id'], "int"));

mysql_select_db($database_auction, $auction);
$Result1 = mysql_query($updateSQL, $auction) or die(mysql_error());
}
}
else

{$warningMessage == "The sale didnt go through because the client ID didnt exist" ;} //else giving the warning message box the value of my message

davidj
05-03-2006, 01:13 PM
try this


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "soldForm") && $totalRows_rst_customers > 0) {

$updateSQL = sprintf("UPDATE stock SET SoldPrice=%s, AuctionDateSold=%s, Sold=%s, ClientID=%s WHERE Id=%s",
GetSQLValueString($_POST['SoldPrice'], "int"),
GetSQLValueString($_POST['AuctionDateSold'], "date"),
GetSQLValueString($_POST['Sold'], "text"),
GetSQLValueString($_POST['ClientID'], "text"),
GetSQLValueString($_POST['Id'], "int"));

mysql_select_db($database_auction, $auction);
$Result1 = mysql_query($updateSQL, $auction) or die(mysql_error());

}
else {$warningMessage = "The sale didnt go through because the client ID didnt exist" ;}/// <<< warning was set to == not =

once you set the value of $warningMessage you need to echo it where you want to display it. Also you need to understand the difference between == and =

== is used as a comparison which returns true or false

example ...
$var = 1 // << this sets $var to 1

if ($var == 1) // << this is checking that $var == (matches) 1

HeadAche
05-03-2006, 01:37 PM
discovered that the totalRows_rst_customers isnt getting its value untill after the the IF and UPDATE statments... Anyone know what I can do to get around this?

HeadAche
05-03-2006, 01:54 PM
Looks more efficient... I shall try that...But i reckon the first way round we were trying to do it might still work, its just that the totalRows value isnt getting set untill further down the page. Can I move the function thats setting the totalRow up or maybe the update function down the page without the whole thing blowing up...

davidj
05-03-2006, 02:10 PM
remember that the PHP engine reads as we do (top to bottom)

make sure it is logical (captain) after you do the move

make sure that rst_customers recordset is before the IF so that totalRows_rst_customers is set

HeadAche
05-04-2006, 12:17 PM
After getting various mad SQL errors, I have managed to move the sql above the update statment. I used your second method of doing the if client exists.

It will send the update through, but I have to press the button twice. This is sort of simillar to the problem i was having with the Jump To record, so I am looking into that to see if there is something I can impliment.

:idea:

davidj
05-05-2006, 07:30 AM
post your code again headache

this is a strange one

HeadAche
05-05-2006, 09:25 AM
Morning mate.... here she is...




<?php require_once('Connections/auction.php'); ?>
<?php $soldTo = $row_rst_MasterView['ClientID']; ?>
<?php $lotPageNo = $_GET['lotPageNo']; ?>
<?php $nextLotNumber = $_GET['LotNo']+1; ?>
<?PHP $sub = $_GET['sub']; ?>
<?PHP IF ($sub == 1) {$nextLotNo = $_GET['LotNo']; } else {$nextLotNo = $_GET['LotNo']+1;}?>

<?PHP session_start();
//declare session display date
$_SESSION['MM_LastPrice'] = $SoldPrice;
$_SESSION['MM_LastCustomerId'] = $ClientID;
$_SESSION['MM_Quant'] = $_GET['available'];
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

// moved it to here********************************************** *****************************************

$maxRows_rst_MasterView = 1;
$pageNum_rst_MasterView = 0;
if (isset($_GET['pageNum_rst_MasterView'])) {
$pageNum_rst_MasterView = $_GET['pageNum_rst_MasterView'];
}
$startRow_rst_MasterView = $pageNum_rst_MasterView * $maxRows_rst_MasterView;

$collot_rst_MasterView = "-1";
if (isset($_GET['LotNo'])) {
$collot_rst_MasterView = (get_magic_quotes_gpc()) ? $_GET['LotNo'] : addslashes($_GET['LotNo']);
}
$coldate_rst_MasterView = "-1";
if (isset($_GET['AuctionHeldIn'])) {
$coldate_rst_MasterView = (get_magic_quotes_gpc()) ? $_GET['AuctionHeldIn'] : addslashes($_GET['AuctionHeldIn']);
}
$colzone_rst_MasterView = "Auction 1";
if (isset($_GET['Zone'])) {
$colzone_rst_MasterView = (get_magic_quotes_gpc()) ? $_GET['Zone'] : addslashes($_GET['Zone']);
}
mysql_select_db($database_auction, $auction);
$query_rst_MasterView = sprintf("SELECT * FROM stock WHERE Zone = '%s' AND AuctionHeldIn = '%s' AND LotNo = '%s' AND Level='1' AND Arrived='1'", $colzone_rst_MasterView,$coldate_rst_MasterView,$c ollot_rst_MasterView);
$query_limit_rst_MasterView = sprintf("%s LIMIT %d, %d", $query_rst_MasterView, $startRow_rst_MasterView, $maxRows_rst_MasterView);
$rst_MasterView = mysql_query($query_limit_rst_MasterView, $auction) or die(mysql_error());
$row_rst_MasterView = mysql_fetch_assoc($rst_MasterView);

if (isset($_GET['totalRows_rst_MasterView'])) {
$totalRows_rst_MasterView = $_GET['totalRows_rst_MasterView'];
} else {
$all_rst_MasterView = mysql_query($query_rst_MasterView);
$totalRows_rst_MasterView = mysql_num_rows($all_rst_MasterView);
}
$totalPages_rst_MasterView = ceil($totalRows_rst_MasterView/$maxRows_rst_MasterView)-1;

$collotno_rst_totalItemIds = "-1";
if (isset($_GET['LotNo'])) {
$collotno_rst_totalItemIds = (get_magic_quotes_gpc()) ? $_GET['LotNo'] : addslashes($_GET['LotNo']);
}
$colzone_rst_totalItemIds = "-1";
if (isset($_SESSION['MM_AuctionZone'])) {
$colzone_rst_totalItemIds = (get_magic_quotes_gpc()) ? $_SESSION['MM_AuctionZone'] : addslashes($_SESSION['MM_AuctionZone']);
}
$coldate_rst_totalItemIds = "-1";
if (isset($_SESSION['MM_AuctionDate'])) {
$coldate_rst_totalItemIds = (get_magic_quotes_gpc()) ? $_SESSION['MM_AuctionDate'] : addslashes($_SESSION['MM_AuctionDate']);
}
$colname_rst_totalItemIds = "-1";
if (isset($row_rst_MasterView['ItemID'])) {
$colname_rst_totalItemIds = (get_magic_quotes_gpc()) ? $row_rst_MasterView['ItemID'] : addslashes($row_rst_MasterView['ItemID']);
}
mysql_select_db($database_auction, $auction);
$query_rst_totalItemIds = sprintf("SELECT * FROM stock WHERE ItemID = '%s' AND AuctionHeldIn = '%s' AND Zone = '%s' and lotno > '%s' and sold = 'NotSold' AND Arrived = '1' AND Level = '1' ", $colname_rst_totalItemIds,$coldate_rst_totalItemId s,$colzone_rst_totalItemIds,$collotno_rst_totalIte mIds);
$rst_totalItemIds = mysql_query($query_rst_totalItemIds, $auction) or die(mysql_error());
$row_rst_totalItemIds = mysql_fetch_assoc($rst_totalItemIds);
$totalRows_rst_totalItemIds = mysql_num_rows($rst_totalItemIds);

$colzone_rst_nextItem = "-1";
if (isset($_GET['Zone'])) {
$colzone_rst_nextItem = (get_magic_quotes_gpc()) ? $_GET['Zone'] : addslashes($_GET['Zone']);
}
$coldate_rst_nextItem = "-1";
if (isset($_GET['AuctionHeldIn'])) {
$coldate_rst_nextItem = (get_magic_quotes_gpc()) ? $_GET['AuctionHeldIn'] : addslashes($_GET['AuctionHeldIn']);
}
$colname_rst_nextItem = "-1";
if (isset($nextLotNumber)) {
$colname_rst_nextItem = (get_magic_quotes_gpc()) ? $nextLotNumber : addslashes($nextLotNumber);
}
mysql_select_db($database_auction, $auction);
$query_rst_nextItem = sprintf("SELECT * FROM stock WHERE LotNo = '%s' AND Zone = '%s' AND AuctionHeldIn = '%s' AND Level='1' AND Arrived='1'", $colname_rst_nextItem,$colzone_rst_nextItem,$colda te_rst_nextItem);
$rst_nextItem = mysql_query($query_rst_nextItem, $auction) or die(mysql_error());
$row_rst_nextItem = mysql_fetch_assoc($rst_nextItem);
$totalRows_rst_nextItem = mysql_num_rows($rst_nextItem);

$colname_rst_LinkedToStock = "-1";
if (isset($row_rst_MasterView['Id'])) {
$colname_rst_LinkedToStock = (get_magic_quotes_gpc()) ? $row_rst_MasterView['Id'] : addslashes($row_rst_MasterView['Id']);
}
mysql_select_db($database_auction, $auction);
$query_rst_LinkedToStock = sprintf("SELECT * FROM stock WHERE LinkedToStockID = '%s' AND Level='2' ORDER BY LinkedToStockID ASC", $colname_rst_LinkedToStock);
$rst_LinkedToStock = mysql_query($query_rst_LinkedToStock, $auction) or die(mysql_error());
$row_rst_LinkedToStock = mysql_fetch_assoc($rst_LinkedToStock);
$totalRows_rst_LinkedToStock = mysql_num_rows($rst_LinkedToStock);

$maxRows_rst_customers = 1;
$pageNum_rst_customers = 0;
if (isset($_GET['pageNum_rst_customers'])) {
$pageNum_rst_customers = $_GET['pageNum_rst_customers'];
}
$startRow_rst_customers = $pageNum_rst_customers * $maxRows_rst_customers;

$colname_rst_customers = "-1";
if (isset($_POST['ClientID'])) {
$colname_rst_customers = (get_magic_quotes_gpc()) ? $_POST['ClientID'] : addslashes($_POST['ClientID']);
}
mysql_select_db($database_auction, $auction);
$query_rst_customers = sprintf("SELECT * FROM customers WHERE CustomerID = '%s'", $colname_rst_customers);
$query_limit_rst_customers = sprintf("%s LIMIT %d, %d", $query_rst_customers, $startRow_rst_customers, $maxRows_rst_customers);
$rst_customers = mysql_query($query_limit_rst_customers, $auction) or die(mysql_error());
$row_rst_customers = mysql_fetch_assoc($rst_customers);

if (isset($_GET['totalRows_rst_customers'])) {
$totalRows_rst_customers = $_GET['totalRows_rst_customers'];
} else {
$all_rst_customers = mysql_query($query_rst_customers);
$totalRows_rst_customers = mysql_num_rows($all_rst_customers);
}
$totalPages_rst_customers = ceil($totalRows_rst_customers/$maxRows_rst_customers)-1;

$colname_rst_bookbid = "-1";
if (isset($row_rst_MasterView['Id'])) {
$colname_rst_bookbid = (get_magic_quotes_gpc()) ? $row_rst_MasterView['Id'] : addslashes($row_rst_MasterView['Id']);
}
mysql_select_db($database_auction, $auction);
$query_rst_bookbid = sprintf("SELECT * FROM bookbids WHERE StockID = '%s' ORDER BY BookBid DESC", $colname_rst_bookbid);
$rst_bookbid = mysql_query($query_rst_bookbid, $auction) or die(mysql_error());
$row_rst_bookbid = mysql_fetch_assoc($rst_bookbid);
$totalRows_rst_bookbid = mysql_num_rows($rst_bookbid);

// the moved stuff ends here********************************************** *****************************************
$testThing = $totalRows_rst_customers;

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
IF ($totalRows_rst_customers == 1) {$warningMessage = "";} else {$warningMessage = "no joy, try a different customer number";} //This is the warning message...

//Sold form update function ************************************************** ***************************************
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "soldForm") && $totalRows_rst_customers == 1)

{
$updateSQL = sprintf("UPDATE stock SET SoldPrice=%s, AuctionDateSold=%s, Sold=%s, ClientID=%s WHERE Id=%s",
GetSQLValueString($_POST['SoldPrice'], "int"),
GetSQLValueString($_POST['AuctionDateSold'], "date"),
GetSQLValueString($_POST['Sold'], "text"),
GetSQLValueString($_POST['ClientID'], "text"),
GetSQLValueString($_POST['Id'], "int"));

mysql_select_db($database_auction, $auction);
$Result1 = mysql_query($updateSQL, $auction) or die(mysql_error());
}
//Sold form update function end ************************************************** **

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "notsoldForm")) {
$updateSQL = sprintf("UPDATE stock SET SoldPrice=%s, AuctionDateSold=%s, Sold=%s, ClientID=%s WHERE Id=%s",
GetSQLValueString($_POST['SoldPrice'], "double"),
GetSQLValueString($_POST['AuctionDateSold'], "date"),
GetSQLValueString($_POST['Sold'], "text"),
GetSQLValueString($_POST['ClientID'], "int"),
GetSQLValueString($_POST['Id'], "int"));

mysql_select_db($database_auction, $auction);
$Result1 = mysql_query($updateSQL, $auction) or die(mysql_error());

$updateGoTo = "/item_masterview.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

?>
<!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=iso-8859-1" />
<title>CSM Plus Ltd - Auction System</title>
<link href="/CSS/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onload="MM_preloadImages('/images/back_on.gif','/images/next_on.gif')">

<?php if ($totalRows_rst_MasterView > 0) { // Show if recordset not empty ?>
Client ID = <?php echo $row_rst_MasterView['ClientID']; ?>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th scope="col">
</th>
</tr>
<tr>
<th scope="col"><marquee>
<span class="style9">Next Item &gt;&gt; Lot:</span> <span class="style6"><?php echo $row_rst_nextItem['LotNo']; ?></span> <span class="style9">Product Code:</span> <span class="style6"><?php echo $row_rst_nextItem['ProductCode']; ?></span> <span class="style9">Description: </span><span class="style6"><?php echo $row_rst_nextItem['Description']; ?></span></marquee> </th>
</tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="99" scope="col"><table width="121" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">/images/tabs/lotno_top.gif</th>
</tr>
<tr>
<td height="67" align="center" class="tabbg"><?php echo $row_rst_MasterView['LotNo']; ?></td>
</tr>
</table></th>
<th scope="col"><table width="121" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">/images/tabs/reserve_top.gif</th>
</tr>
<tr>
<td height="67" align="center" class="tabbg">&pound;<?php echo $row_rst_MasterView['ReservePrice']; ?></td>
</tr>
</table></th>
<th scope="col"><table width="121" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">/images/tabs/incomplot_top.gif</th>
</tr>
<tr>
<td>/images/tabs/<?php echo $row_rst_MasterView['CompleteLot']; ?>incomplot_bottom.gif</td>
</tr>
</table></th>
<th scope="col"><table width="121" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">/images/tabs/sold_top.gif</th>
</tr>
<tr>
<td>/images/tabs/<?php echo $row_rst_MasterView['Sold']; ?>_bottom.gif</td>
</tr>
</table></th>
</tr>
</table></th>
</tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th colspan="2" scope="col"><table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th align="left" scope="col"><?php echo $_SESSION['MM_AuctionDate']; ?><?php echo $_SESSION['MM_AuctionZone']; ?></th>
</tr>
</table></th>
</tr>
<tr>
<th width="50%" valign="top" scope="col">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th align="left" bgcolor="#999999" class="style5 style7" scope="col">Product Code</th>
</tr>
<tr>
<th align="left" scope="col"><span class="style3"><?php echo $row_rst_MasterView['ProductCode']; ?></span></th>
</tr>
<tr>
<th align="left" bgcolor="#999999" scope="col"><span class="style5 style7">Description</span></th>
</tr>
<tr>
<th align="left" scope="col"><span class="style3"><?php echo $row_rst_MasterView['Description']; ?></span></th>
</tr>
<tr>
<th align="left" bgcolor="#999999" scope="col"><span class="style5 style7">Incomplete Reason </span></th>
</tr>
<tr>
<th align="left" scope="col"><span class="style3"><?php echo $row_rst_MasterView['IncompleteReason']; ?></span></th>
</tr>
<tr>
<th align="left" bgcolor="#999999" scope="col"><span class="style5 style7">VAT Flag </span></th>
</tr>
<tr>
<th align="left" scope="col">
/images/<?php echo $row_rst_MasterView['VATProductFlag']; ?>VAT.gif</th>
</tr>
<tr>
<th align="left" bgcolor="#999999" scope="col"><span class="style5 style7">How many more available...</span></th>
</tr>
<tr>
<th align="left" scope="col">
<?php if ($totalRows_rst_totalItemIds > 0) { // Show if recordset not empty ?>
<?php echo $totalRows_rst_totalItemIds ?>
<?php } // Show if recordset not empty ?> </th>
<?PHP session_start();
$_SESSION['MM_Quant'] = $totalRows_rst_totalItemIds;
?>
</tr>
<tr>
<th align="left" bgcolor="#999999" scope="col"><span class="style5 style7">Also includes <?php echo $totalRows_rst_LinkedToStock ?> more items </span></th>
</tr>
<tr>
<th align="left" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td class="style3"><?php echo $row_rst_LinkedToStock['Description']; ?></td>
</tr>
<?php } while ($row_rst_LinkedToStock = mysql_fetch_assoc($rst_LinkedToStock)); ?>
</table></th>
</tr>
<tr>
<th align="left" scope="col"></th>
</tr>
<tr>
<th align="left" scope="col"></th>
</tr>
<tr>
<th align="left" scope="col"></th>
</tr>
</table></th>
<th width="50%" valign="top" scope="col"><table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col">

</p>


/images/products/<?php echo $row_rst_MasterView['Id']; ?>.jpg</p></th>
</tr>
</table> </th>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="236" valign="top" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
<th height="124" colspan="2" align="center" valign="top" scope="col"><table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="300" align="left" valign="top" scope="col"><table width="250" border="0" cellspacing="0">

<tr>
<th colspan="2" align="center" valign="bottom" scope="col"> <fieldset>
<legend class="style9">Sell Price & Customer ID</legend>
<form action="<?php echo $editFormAction; ?>" name="soldForm" id="soldForm" method="post">
<table width="100%" border="0" cellspacing="0">
<tr>
<th width="50%" align="left" scope="col">Sold Price </th>
<th width="50%" align="left" scope="col">Customer ID </th>
</tr>
<tr>
<td width="50%" align="left">&pound;
<input name="SoldPrice" type="text" id="SoldPrice" onfocus="if(this.value=='')this.value='';" value="" size="5" maxlength="5" /></td>
<td width="50%" align="left"><input name="ClientID" type="text" id="ClientID" onfocus="if(this.value=='')this.value='';" size="5" maxlength="5" />
<input name="sub2" type="hidden" id="sub2" value="1" />
<input name="Id" type="hidden" id="Id" value="<?php echo $row_rst_MasterView['Id']; ?>" />
<input name="Sold" type="hidden" id="Sold" value="Sold" />
<input name="AuctionDateSold" type="hidden" id="AuctionDateSold" value="<?php echo date("Y-m-d"); ?>" /> </td>

</tr>
</table>

<input type="submit" name="Submit" value="SELL to customer" />
<input type="hidden" name="MM_update" value="soldForm" />
<input type="hidden" name="MM_update" value="soldForm">

<?php echo $warningMessage; ?>
</form>
</fieldset></th>
</tr>
<tr>
<th colspan="2" align="center" valign="bottom" scope="col"> </th>
</tr>
<tr>
<th colspan="2" align="center" valign="bottom" scope="col"> </th>
</tr>
</table></th>
<th width="300" align="left" valign="top" scope="col"><table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><fieldset>
<legend class="style9">Change to Not Sold</legend>
<form name="notsoldForm" id="notsoldForm" method="POST" action="<?php echo $editFormAction; ?>">
<table width="250" border="0" cellspacing="0">
<tr>
<th width="54%" align="center" scope="col"><span class="style5">Sold / Not Sold</span></th>
<th width="46%" align="center" scope="col">/images/<?php echo $row_rst_MasterView['Sold']; ?>.gif</th>
</tr>
<tr align="center">
<td colspan="2">



<input type="submit" name="Submit" value="Change to NOT SOLD" />
<input name="Id" type="hidden" id="Id" value="<?php echo $row_rst_MasterView['Id']; ?>" />
<input name="Sold" type="hidden" id="Sold" value="NotSold" />
<input name="AuctionDateSold" type="hidden" id="AuctionDateSold" />
<input name="ClientID" type="hidden" id="ClientID" />
<input name="SoldPrice" type="hidden" id="SoldPrice" />
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="notsoldForm" />
</form>
</fieldset></th>
</tr>
</table></th>
</tr>
</table></th>
<th align="center" valign="bottom" scope="col"><table width="350" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="20%" scope="col"><span class="style5">/images/back_off.gif (/item_masterview.php?LotNo=<?php echo $row_rst_MasterView['LotNo'] -1; ?>&amp;Zone=<?php echo $_SESSION['MM_AuctionZone']; ?>&amp;AuctionHeldIn=<?php echo $_SESSION['MM_AuctionDate']; ?>&amp;Level=1&amp;Arrived=1&amp;Arrived=1&amp;ItemID=<?php echo $row_rst_MasterView['ItemID']; ?>)</span></th>
<th width="60%" scope="col"><form name="lotnumberjump" id="lotnumberjump" method="GET" action="/item_masterview.php?LotNo=<?php echo $lotPageNo ; ?>&Zone=<?php echo $_SESSION['MM_AuctionZone']; ?>&AuctionHeldIn=<?php echo $_SESSION['MM_AuctionDate']; ?>&Level=1&Arrived=1">
<span class="style9">GOTO</span>
<input name="LotNo" type="text" id="LotNo" size="4" />

<input name="GO" type="submit" id="GO" value="GO" />
<input name="sub" type="hidden" id="sub" value="1" />
<input name="Arrived" type="hidden" id="Arrived" value="1" />
<input name="Level" type="hidden" id="Level" value="1" />
<input name="AuctionHeldIn" type="hidden" id="AuctionHeldIn" value="<?php echo $_SESSION['MM_AuctionDate']; ?>" />
<input name="Zone" type="hidden" id="Zone" value="<?php echo $_SESSION['MM_AuctionZone']; ?>" />
</form></th>
<th width="20%" scope="col"><span class="style5">/images/next_off.gif (/item_masterview.php?LotNo=<?php echo $row_rst_MasterView['LotNo'] +1; ?>&amp;Zone=<?php echo $_SESSION['MM_AuctionZone']; ?>&amp;AuctionHeldIn=<?php echo $_SESSION['MM_AuctionDate']; ?>&amp;Level=1&amp;Arrived=1&amp;ItemID=<?php echo $row_rst_MasterView['ItemID']; ?>)</span></th>
</tr>
<tr align="center">
<th colspan="3" scope="col"><form name="form1" id="form1" method="post" action="/sell_more.php?Zone=<?php echo $_SESSION['MM_AuctionZone']; ?>&AuctionHeldIn=<?php echo $_SESSION['MM_AuctionDate']; ?>&LotNo=<?php echo $row_rst_MasterView['LotNo']; ?>&ItemID=<?php echo $row_rst_MasterView['ItemID']; ?>" target="_blank">
Sell

<input name="available" type="text" id="available" value="<?php echo $totalRows_rst_totalItemIds ?>" size="3" />

<input name="submit" type="submit" id="submit" value="more to client" />
</form>
<?php echo $_SESSION['MM_LastPrice']; ?>*<?php echo $_SESSION['MM_LastCustomerId']; ?>

<?php echo $_SESSION['MM_Quant']; ?></th>

</tr>
</table></th>
</tr>
</table></th>
</tr>
<tr>
<th width="50%" height="19" align="right" valign="top" class="style9" scope="col"></th>
<th width="442" height="19" colspan="-1" align="center" valign="top" scope="col"></th>
</tr>
<tr>
<th height="19" colspan="2" align="center" valign="top" scope="col"><?php echo $totalRows_rst_customers ?> <?PHP echo $testThing; ?></th>
</tr>
<tr>
<th height="19" colspan="2" scope="col">

<input type="button" value="Close Window" onclick="javascript:self.close();" />
</p>
</th>
</tr>
</table></th>
</tr>
</table>
<?php } // Show if recordset not empty ?>




<?php if ($totalRows_rst_MasterView == 0) { // Show if recordset empty ?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">

</p>


</p>


There is no lot number following on from the last one. Please close this window and select the next lot from the list view.

</p>




<input type="button" value="Close Window" onclick="javascript:self.close();" />
</p></td>
</tr>
</table>
<?php } // Show if recordset empty ?>
<!--
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><span class="style6">!</span> There are no more items in this lot



Options

<span class="style5">Go back to last lot item (javascript:history.go(-1);)

Close this window and goto list view (javascript:window.close();)

Go to date select page and select new auction date / zone. </span></th>
</tr>
</table>
-->
</p>
</body>
</html>
<?php
mysql_free_result($rst_MasterView);

mysql_free_result($rst_totalItemIds);

mysql_free_result($rst_nextItem);

mysql_free_result($rst_LinkedToStock);

mysql_free_result($rst_customers);

mysql_free_result($rst_bookbid);
?>

davidj
05-05-2006, 10:22 AM
i cant see the wood for the trees

i will check this out later but may have to be the weekend if you can wait

i did notice this...

IF ($totalRows_rst_customers == 1) {$warningMessage = "";} else {$warningMessage = "no joy, try a different customer number";} //This is the warning message...

what happens if $totalRows_rst_customers == 2 then your warning message is set to "nothing" ? is this what you wanted?

if your checking to see if a customers exists then you need to write your condition like ...IF ($totalRows_rst_customers > 0)

also you have this...


<?php require_once('Connections/auction.php'); ?>
<?php $soldTo = $row_rst_MasterView['ClientID']; ?>
<?php $lotPageNo = $_GET['lotPageNo']; ?>
<?php $nextLotNumber = $_GET['LotNo']+1; ?>
<?PHP $sub = $_GET['sub']; ?>
<?PHP IF ($sub == 1) {$nextLotNo = $_GET['LotNo']; } else {$nextLotNo = $_GET['LotNo']+1;}?>

<?PHP session_start();
//declare session display date
$_SESSION['MM_LastPrice'] = $SoldPrice;
$_SESSION['MM_LastCustomerId'] = $ClientID;
$_SESSION['MM_Quant'] = $_GET['available'];
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;


I have seen cleaner bomb sites.
give yourself a kidney punch from me as punishment and try this..


<?php /// << only one of these needed to start php and one close (?>) before html start.

require_once('Connections/auction.php');
$soldTo = $row_rst_MasterView['ClientID'];
$lotPageNo = $_GET['lotPageNo'];
$nextLotNumber = $_GET['LotNo']+1;
$sub = $_GET['sub'];
IF ($sub == 1) {$nextLotNo = $_GET['LotNo']; } else {$nextLotNo = $_GET['LotNo']+1;}

session_start();
//declare session display date
$_SESSION['MM_LastPrice'] = $SoldPrice;
$_SESSION['MM_LastCustomerId'] = $ClientID;
$_SESSION['MM_Quant'] = $_GET['available'];


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

etc


also please start using comments and explain what each bit does as you write it. Even if your the only one that has access to the code you will find it very usefull in about 6 months when you tweak it or add a mod

HeadAche
05-05-2006, 11:21 AM
OK... waiting shouldnt be a problem man. Ive been pulled off this one for today and return to the more familliar game of designing, doin a logo for someone who sharpens hair dressers scissors for a living (yeah I know, WHAT!).


what happens if $totalRows_rst_customers == 2 then your warning message is set to "nothing" ? is this what you wanted?


No, lol... this is the other problem but its insignifigant compaired to the Update issue. I want the message to have the value only IF $totalRows == 0 after the Update has gone through with a customerID that doesnt exist. I want $warningMessage to = ""; when the page is either A. opened and B. when an Update with a customerID that does exist has gone though.

$totalRows will never be more than 1 becasue the CustomerID's are unique (the other lads VB program handles the input of customer #'s)


I have seen cleaner bomb sites.
give yourself a kidney punch from me as punishment and try this..


I cleaned this up before I posted it :oops: Putting seperate things in their own <? ?> tags was serving the same principle to me as //comments... :oops: :oops: Shall start using the comments. Like you say, its in my best interest. Ill save the kidney punch till after ive had a few pints....

davidj
05-05-2006, 03:17 PM
next tip:

how to write a sexy update statement without DW ballast

maybe even take you into the realms of OOP PHP.

You will never look back...

HeadAche
05-05-2006, 03:43 PM
next tip:

how to write a sexy update statement without DW ballast

maybe even take you into the realms of OOP PHP.

You will never look back...
next tip:

how to write a sexy update statement without DW ballast

maybe even take you into the realms of OOP PHP.

You will never look back...



Yes please... I am getting abit fed up already with the limited things you can do in DW, its almost not worth using them... I would love to learning the proper s*it, most web designers will probably have to if they want to stay in the game for much longer.

HeadAche
05-08-2006, 09:26 AM
:D Hello.... any chance mate :lol:

davidj
05-09-2006, 07:37 AM
not reall had a chance to look

have been really busy and dont have the interweb in my temporary home so the only time i get to answer Q's is when i steal 10 mins here and there

HeadAche
05-09-2006, 10:32 AM
Alright mate, nah worries. Appreciate all you have done so far. I'll keep on trying to wreck my head over it see what I can achieve.. I found a copy of PHP and MySQL for dummies the other day that I forgot I had 8) got upto arrays so far.

Again though, this is something that I feel should be something in the server behavours in DW along with multiple update / records @ once. What pile of sh*t, they need me on their R&D team.

davidj
05-09-2006, 10:41 AM
multiple update / records @ once. What pile of sh*t, they need me on their R&D team.

just add your update statement inside a FOR loop or a WHILE loop..

HeadAche
05-09-2006, 02:30 PM
OK. any other noobs that want to do this you can ask me if thee wish as I have finaly got the damn thing working.


@DJ - check out my snazzy error message code, I know its simple but im well proud.

outline - error message should be set to nothing when the page loads. The page checks that the update form has been pressed by checking for $soldSub hidden form field, which has the value of 1. The code then goes on to check if $totalRows_rst_customers ALSO (&&) is == 1 OR == 0 (meaning the client is in the base or the client number isnt in the base)


if ( ($soldSub == 1) && ($totalRows_rst_customers == 0) ) {$warningMessage = "Customer doesn't exist";}
else if ( ($soldSub == 1) && ($totalRows_rst_customers == 1) ) {$warningMessage = "";}
else {;} //setting the warning message.


I could make is so the message says client does exist when the sale has gone through I guess but I already have a green tick image displaying when an item has been sold so theres no point really.

:P

davidj
05-09-2006, 02:56 PM
headache

try this for your warnings...

create a seperate file which just contains warnings but define them like so...


<?php
define ("U8016", "Unauthorised Access");
define ("U8017", "Unable to establish a database connection");
define ("U8018", "Unable to locate user object");
define ("U8019", "Invalid Login ID");
?>
etc etc


this file just contains warnings and other messages that you can use throughout your app

then include the file into your pages (like any other include)

then you can just echo U8019; which will output the message "Invalid Login ID"

this is great for audits and maintenance and it keeps everything in one place.. remember, a tidy application is a happy application!

you can also add true to a define..

define ("U8019", "Invalid Login ID", true);

this will render the define handle case-insensitive