Jump to content

~ php help with $_GET["id"] ~


Go to solution Solved by ginerjm,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/289684-~-php-help-with-_getid-~/
Share on other sites

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

  • Solution

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 by ginerjm
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.