Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding string to a sql string

Status
Not open for further replies.
Mar 26, 2001
17
US
Hi All,
I'm trying to add a string into an already existing string. I want to pretty much have the following string

Code:
$sql_ad = "SELECT * FROM Ad WHERE";
$sql_ad = $sql_ad." StateIDKeyRef='$StateID'";  
           // sql_ad + "(another string)"

to attain this string exactly
Code:
$sql_ad = "SELECT * FROM Ad WHERE StateIDKeyRef='$StateID'";

When I run the joint string above, it gives me SQL syntax error. I really don't know if I'm joining the string correctly, or is it SQL that is giving me the problem?

Thank you in advance for your help
 
He has the space at the start of the next string, but yeah, try echoing the string and checking what it turns out as.
 
I think you're mis-reading the code sleipnir...

$sql_ad = "SELECT * FROM Ad WHERE";
$sql_ad = $sql_ad." StateIDKeyRef='$StateID'";

is functionally equivalent to

$sql_ad = "SELECT * FROM Ad WHERE";
$sql_ad .= " StateIDKeyRef='$StateID'";

There's no doubt that your other two tips however will reveal what's going on.

-Rob
 
I haven't a clue what went wrong... but I used

Code:
$sql_ad = "SELECT * FROM Ad WHERE";
$sql_ad .= " StateIDKeyRef='$StateID'";

and it echoed
Code:
SELECT * FROM Ad WHERE StateIDKeyRef='37'

Worked out perfect, ran the statement and it queried perfectly. Thanks everyone for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top