singhy Posted July 10, 2014 Share Posted July 10, 2014 hi all new to webforum and php, how can I enter $_get['id] as I know this id...my code snippet is below $sql = "SELECT x,y,z from tablename WHERE Id='" . $_GET["id"] . "'"; It works fine as it is getting the variable from a another webpage, but I know an id and want to enter it manually just to check a different webpage , thanks in advance....singhy Please give example if the known id=xyztest Quote Link to comment https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/ Share on other sites More sharing options...
cyberRobot Posted July 10, 2014 Share Posted July 10, 2014 Are you getting any errors? If not, have you checked if there are any MySQL errors? I'm not sure if you're using MySQL, MySQLi, or PDO, but they all have a function for showing errors after a query is processed. Here is the function for MySQL: http://www.php.net/manual/en/function.mysql-error.php Quote Link to comment https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/#findComment-1484539 Share on other sites More sharing options...
Solution ginerjm Posted July 10, 2014 Solution Share Posted July 10, 2014 (edited) Try modifying your code like this: $my_id = "xyztest"; if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = $my_id; } $sql = "Select x,y,z from tablename where Id='$id'"; This will use the $_GET value if provided, otherwise your value. Of course you really need to add some code to secure yourself from injection by using prepared statements (mysqlI or PDO AND NOT MYSQL_* functions). Otherwise you're just asking for a hacker to invade your data. Edited July 10, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/#findComment-1484559 Share on other sites More sharing options...
singhy Posted July 11, 2014 Author Share Posted July 11, 2014 hi cyberrobot thanks for the reply, I am using php and MySQL, the info given very helpful, thanks singhy Quote Link to comment https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/#findComment-1484652 Share on other sites More sharing options...
singhy Posted July 11, 2014 Author Share Posted July 11, 2014 Hi GinerJim thanks for the quick response and for the code snippet, it worked a treat, thanks for your help singhy Quote Link to comment https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/#findComment-1484653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.