Forum Moderators: coopster

Message Too Old, No Replies

Why doesnt this pick up the $dbfirstnamr var?

Coding Error?

         

OpalRec

9:03 am on Apr 4, 2011 (gmt 0)

10+ Year Member



$DBFirstName = (string) trim($_POST[FirstName]);
$DBLastName = (string) trim($_POST[LastName]);
$DBEmail = (string) trim($_POST[Email]);

$query="SELECT * FROM cdata WHERE FirstName='$DBFirstName' || LastName='$DBLastName' || Email='$DBEmail'" ;

$result = mysql_query($query) or die(mysql_error());

The above code snipit works when Lastname or Email exist in the DBm but not with Firstname. Any ideas anyone?

Matthew1980

1:34 pm on Apr 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there OpalRec,

Welcome to WebmasterWorld!

Your code:-

//typecasting not needed as default type from form is string...
//need to have the quotes there too - else assumed constant - error_reporting(E_ALL) would detect //that

$DBFirstName = trim(strip_tags($_POST['FirstName']));
$DBLastName = trim(strip_tags($_POST['LastName']));
$DBEmail = trim(strip_tags($_POST['Email']));

$query = "SELECT * FROM `cdata` WHERE `FirstName` = '".$DBFirstName."' or `LastName` = '".$DBLastName."' or `Email` = '".$DBEmail."' ";

$result = mysql_query($query) or die(mysql_error());

Check your data getting through, ensure that your vars are populated as expected, then carry on.

Cheers,
MRb

OpalRec

8:24 am on Apr 5, 2011 (gmt 0)

10+ Year Member



Thanks MRb

That solved the problem. I only started teaching myself PHP 2 weeks ago, so expect a few more Newbie questions.

Matthew1980

11:54 am on Apr 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cool! Glad that it did the job, we all have to start somewhere don't we :)

Enjoy the learning curve.

Cheers,
MRb