Page 1 of 1

How do I insert a page variable into SQL please?

Posted: Wed Jul 28, 2004 2:11 am
by ChrisN
Please bear with me I am a newbie
I have a variable [MembNo ] carried forward from a form see below:

Your Membership Number is <?php echo $_POST["MembNo"]; ?>.<br>

I want to retrieve Firstname from the database and insert it into the page

$sql="SELECT Firstname FROM Officerquery WHERE MembershipNo = "$_POST["MembNo"]"";
$rs=odbc_exec($conn,$sql); if (!$rs)


What is the correct syntax for 'WHERE MembershipNo = 'please

Posted: Wed Jul 28, 2004 2:30 am
by markl999
$sql="SELECT Firstname FROM Officerquery WHERE MembershipNo = '{$_POST['MembNo']}'";

or

$sql="SELECT Firstname FROM Officerquery WHERE MembershipNo = '".$_POST['MembNo']."'";

Posted: Wed Jul 28, 2004 2:55 am
by ChrisN
Thanks Mark I will try both of them but briefly, what is the different about the way each handles the job?

Posted: Wed Jul 28, 2004 12:33 pm
by markl999
They are both just two ways of doing the same thing and it's down to personal preference as to which you use.
The first uses complex syntax and the second uses basic concatentation.

Posted: Thu Jul 29, 2004 2:35 pm
by ChrisN
Thanks for that. The complex gives no result but the simple gives me an answer (it aint wot I want, but at least it gives a window(forgive the pun)on where to go from here
ChrisN