PDA

View Full Version : PHP form validation.


HeadAche
05-15-2006, 12:59 PM
Just when I thought I was starting to get my head around it ive got another headache... does anyone know what is wrong with this statment. I trying to set the var $saleFlag to "NOTOK" if the form fields soldprice AND OR client ID are either empty or dont have just numbers in... It sill allows it to be submitted though...


$soldFlag = "OK";

if ($soldSub == 1)
{
if (empty($SoldPrice) || empty($ClientID)) {$soldFlag = "NOTOK";}
elseif (!ereg("[0-9]",$SoldPrice) || !ereg("[0-9]",ClientID)) {$solfFlag = "NOTOK";}
else
{
if($totalRows_rst_customers == 0) {echo "Customer doesn't exist";}
else if ($totalRows_rst_customers == 1) {$warningMessage = "";}
}
}

then in my update statment I just have update only if blah blah && ($soldFlag == "OK" etc...

davidj
05-16-2006, 09:26 AM
if (empty($SoldPrice) || empty($ClientID)) {$soldFlag = "NOTOK";}


is this what your after...
if (!$SoldPrice || !$ClientID) {$soldFlag = "NOTOK";}
or

if ($SoldPrice=='' || $ClientID=='') {$soldFlag = "NOTOK";}

HeadAche
05-16-2006, 11:26 AM
alright mate.

ive been trying to get this validation going using the eld hidden field = 1 trigger ou taught for 3 days, 3 ****ing days wasted... I admit defeat. check this out, whats wrong with this ATALL.


if ( ($soldSub == 1) && ($soldPrice == "") || ($clientID == "") ) {$soldFlag = "NO";} else {$soldFlag = "OK";}


this pumps out NO when the page loads, which it shouldnt, and even when I submit an update with a price and valid client ID, it will still pump out NO...


if ( ($soldSub == 1) && ($soldPrice == ' ') || ($clientID == ' ') ) {$soldFlag = "NO";} else {$soldFlag = "OK";}


If I change it slightly to the above, I constantly get OK

!$var I get constant NO's & (empty($var)) constant NO's

Ive tried this in sh*tloads of different styles, using if's, elseif's, empty(), !empty(), =="", ==' ', just tried the !$soldPrice, and nothing will work.

3 days trying to put a check on 2 input boxs for nothing entered and if it was a number entered... Totaly give up, im just gonna have to explain that when they get the mySQL error on line 1 message that they must have put something wrong in and have to press delete key to go back and do it again.

Either my 'logic' is tripping me up, or the code in there Dreamweaver puts in is holding everything back, probably both.

RIGHT, get this, even the b*stard client side Javascript validation wont work. set soldprice and clientid as required and as numbers, and the form will still kick out an alert even when you have entered numbers in both... Yaromat's validation (dont know if you are familiar with it) has always been iff'y but for the record doesnt work either...


Today, I HATE computers.
:evil: :evil: :evil:

davidj
05-16-2006, 11:37 AM
echo out all your vars to determin what they contain

HeadAche
05-16-2006, 11:50 AM
done - thats how I know if im getting the NO or the OK value...

davidj
05-16-2006, 11:53 AM
if ( ($soldSub == 1) && ($soldPrice == "") || ($clientID == "") ) {$soldFlag = "NO";} else {$soldFlag = "OK";}

please examine the logic...

if ( $soldSub == 1 && $soldPrice == "" || $clientID == "" ) {$soldFlag = "NO";} else {$soldFlag = "OK";}

are you sure 100% that the logic is correct

HeadAche
05-16-2006, 12:21 PM
:cry: :cry: :cry:

Yep, 100% mate. Just pasted what you posted without all the extra () i had in mine and it is still constantly kicking out NO, even when the page has loaded which it shouldnt because obviously $soldSub hasnt been submitted yet. I am echoing $soldSub aswell and this is printing 1 on screen when it should.



I was testing out my if statments this morning with simpler versions like $var = 64 , if var == 64 then this that and the other, just to make sure I was writing them correctly, and they worked a treat. Get into trying to do this and it goes to ***t. Writing if statments it almost second nature now, trying to do this validating has proper reight taken the wind out of me...

HeadAche
05-16-2006, 12:40 PM
whats wrong with this? I know there are different / more efficient ways of writting it, but shouldnt this work?


if ( $soldSub == 1 && $soldPrice == "" || $clientID == "" ) {$soldFlag = "NO";} else {$soldFlag = "OK";}
if ($soldSub == 1 && !is_numeric($soldPrice) || !is_numeric($clientID) ) {$soldFlag = "NO";} else {$soldFlag = "OK";}


if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "soldForm") && ($totalRows_rst_customers == 1) && ($soldFlag == "OK") )

{
$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'], "text"),
GetSQLValueString($_POST['Id'], "int"));

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