$_GET and mysql?

Status
Not open for further replies.

GarettM

Posting Freak
Aug 5, 2010
833
136
Can i use $_GET to fetch arrays?

say $_GET['username']
if(!$_GET['username'])
{
die();
} else {
("SELECT * FROM `users` WHERE `examplename` = ".$_GET['username']."")
}

Can you do this or is it a stupid way of fetching user information?
 

Feedback

Haboa Hotel
Jun 11, 2012
80
14
I'm rusty with PHP, but there is better ways of fetching user information, like using OOP, and sessions.. But, your code wouldn't really work, as I don't understand why you would have to do it like that, something more simple, IMO, would be;
PHP:
if($_GET['username'])
{
mysql_query('SELECT * FROM users WHERE examplename = '" . $_GET['username'] . "'');
} else {
die();
}

But, using sessions will only allow users to access a page, if that's what you want. (Session, else die.)

It really depends on how you want it coded.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
PHP:
<?php
if (isset( $_GET['username'] ))
{
    $user = mysql_real_escape_string( $_GET['username'] );
    $checkQ = @mysql_query( "SELECT * FROM `users` WHERE `username` = '" . $user . "' LIMIT 1" );
    if (mysql_num_rows( $checkQ ) == 0)
    {
        echo 'This user does not exist.';
    }
    else
    {
        $row = @mysql_fetch_array( $checkQ );
        echo $row['email'] . '<br />';
        echo $row['joindate'] . '<br />';
        echo $row['rank'];
    }
}
else
{
    echo 'No username set.';
}
?>

Should do it I think.
 

GarettM

Posting Freak
Aug 5, 2010
833
136
Thanks Monsta But i already Codded what i needed codded
but i am gonna use the $user = mysql_real_escape_string( $_GET['username'] ); Do You want credits in the profile page ;P
 

brsy

nah mang
May 12, 2011
1,530
272
Thanks Monsta But i already Codded what i needed codded
but i am gonna use the $user = mysql_real_escape_string( $_GET['username'] ); Do You want credits in the profile page ;P
Why not make a secure function?

PHP:
function secure($str) {
  mysql_real_escape_string(htmlentities($str));
}
 
Status
Not open for further replies.

Users who are viewing this thread

Top