Hello, I am new in php may be this one may be pretty much easy for you, but I'm stuck here I have a $_get value $varialbe which is being use in mysql query in where = '$variable' if it doesn't match any where value, it returns error.
Asked
Active
Viewed 299 times
0
-
Try posting some of your code, so we have a better understanding of what you're trying to do. You can also add tags for `php` and `mysql` to your question to get a wider audience. – tomlogic Feb 14 '12 at 23:12
1 Answers
1
Tutorials abound on this subject and hundreds of questions exist about getting started with PHP and passing variables into MySQL queries, etc.
Are you sure you've been through a few of those?
Variables from an HTML form passed as part of the URL get put into a $_GET
array by PHP. So if you have a textbox with a name of "age" and a user submits it with a value of "20" you will see this URL:
http://domain.com/page.php?age=20
This value will be accessible using $_GET['age']
in PHP. To pass this value to MySQL you then would incorporate the value into the query, but only after doing some basic security and sanitizing!
$age = mysql_real_escape_string($_GET['age']);
Your MySQL query can then use this value like so:
$query = "SELECT FROM table WHERE age = $age;";
$result = mysql_query($query) or die(mysql_error());
Post your code and actual error messages for more specific answers and assistance.
-
I have a download.php file which takes id parameter from hyperlink like this.(http://mydomain.com/download.php?someid=23)and m saving id in $var = $_get['someid']; and making a query to database like this $query = mysql_query("select * from table_name where id = '$var' ")or die mysql_error()); i also tried [ where id = $var ] with-out single quotes.the problem is when i put another id manually in url which doesn't exist in database then query returns an error.even not working die(); please give any suggestion. – user838037 Feb 15 '12 at 08:12