[SOLVED] How do I insert a page variable into SQL please?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChrisN
Forum Newbie
Posts: 3
Joined: Wed Jul 28, 2004 2:11 am
Location: UK

How do I insert a page variable into SQL please?

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

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

or

$sql="SELECT Firstname FROM Officerquery WHERE MembershipNo = '".$_POST['MembNo']."'";
ChrisN
Forum Newbie
Posts: 3
Joined: Wed Jul 28, 2004 2:11 am
Location: UK

Post by ChrisN »

Thanks Mark I will try both of them but briefly, what is the different about the way each handles the job?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
ChrisN
Forum Newbie
Posts: 3
Joined: Wed Jul 28, 2004 2:11 am
Location: UK

Post 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
Post Reply