Multiple PHP variables in MYSQL query with AND condition -
This is my first code-question! I'm starting both on MySQL and PHP, so it can be really simple! This is my code:
This is a file included in my index.php ...
And these are the defined variables with the $ _GET function:
& lt ;? Php $ type = $ _ GET ['type']; $ Fruit = $ _ receive ['fruit']; $ Country = $ _ received ['country']; ? & Gt; And then later I will bring the array and work with it.
The problem is that my $ query works just fine with '$ type'-variable, but not with $ country- -able - - - - - - or I have tried any other Variable
I use Microsoft Webmatrix and it tells me that this problem arises very momentarily in $ $ - Sign in to the second variable ...
So much confused In! Hope you can help a newcomer :)
Edit: I came to know that the problem was with "ticks" around my variable, with the backing up (``) is. In addition, I started using my SQL instead of PDO and MySQLi. For beginners, MySQLi is probably the easiest
Just a few (significant) points to note .. .
-
You probably have to use mysqli_ * functions instead of mysql_functions, because they are going to be deprecated in the following release.
-
Before starting DB questions, there is a good habit of getting started early, and in the long run you will save many headaches!
Select, type = '% s' and country = '% s' ", mysqli_real_escape_string ($ db_object, $ type), Mysqli_real_escape_string ($ db_object, $ country)); $ Result = mysqli_query ($ db_object, $ sql);
ps using my $ db_object call ()
Edit:
in my example (soon Mysql_functions for example, for example the following:
$ sql = sprintf ("Choose from wines where type = '% s' and country =' % S '", mysql_real_escape_string ($ type), Mysql_real_escape_string ($ country)); $ Result = mysql_query ($ sql);
Comments
Post a Comment