Re: how to use PHP variable in MYSQL query?
FIRST OF ALL: I've read this entire thread and nothing anyone has suggested has worked. I did see one thing with substituting '=' with '=='. What does '==' mean?
I have the following code that works:
=============================================
<?PHP
// Manually load User Variable
$test = 'TX';
// Query Database with hard-coded value in WHERE clause
$quer5 = mysql_query('SELECT * FROM `jobs` WHERE `state` = "TX" ORDER BY `city`');
// Get output
while($rowtest = mysql_fetch_array($quer5)) {
echo ("$rowtest[city]"."<br>");
}
?>
===============================================
This PHP 4x/MySQL (version ?) website was setup by someone else and several people have worked on it before I was called in to troubleshoot. It is a mess.
The MySQL db is utf8_unicode.ci, but all the tables are collated as latin_swedish_ci. I am running the above test and it works with the current configuration. The site is large and the client will NOT pay to have a total re-work (which we all know it needs).
The site is hosted at AT&T Web Hosting - not fun!
MY PROBLEM:
In the above test, I create and manually load a User Variable ($test). I've tested the variable and it is storing and returning the value "TX" just fine.
In the Query WHERE clause, I need to substitute "TX" with the $test variable.
I've tried single quotes, double quotes, no quotes, escape strings, everything I can think of trying.
I'm open to suggestions. What should I sub for
WHERE `state` = "TX"
to make the Query use the $test variable?
Subject
Written By
Posted
February 01, 2008 12:15AM
November 13, 2008 02:52PM
December 20, 2008 04:57PM
February 07, 2009 09:05AM
February 07, 2009 10:48PM
February 12, 2009 03:10AM
February 12, 2009 03:34AM
February 26, 2009 11:15AM
Re: how to use PHP variable in MYSQL query?
February 28, 2009 11:32PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.