Jump to content

[SOLVED] getting variable from url address


gsquare567

Recommended Posts

$result = mysql_query("SELECT * FROM AuthDB WHERE Username = $_GET['username']");

 

this does not work. in the address bar i typed in http://localhost/abc.php?username=Test

am i using the GET wrong?

 

Oh man! You best not do that! That is generally a bad idea! You want to control what your user puts into your query. Never put direct user info into a query!

<?

$find_user = $_GET['username'];

$query = mysql_query("SELECT * from AuthDB WHERE Username = '$find_user'") or die(mysql_error());

$row = mysql_fetch_array( $query );

$user_check = $row["id"];

if($user_check=="") { echo"Invalid Username"; exit; }

else { //carry out what ever

}

?>

I tried doing this

$query = mysql_query("SELECT * from AuthDB WHERE Username = $_GET['username']") or die(mysql_error()); 

once but it didn't work but than i tried

$find_user = $_GET['username'];
$query = mysql_query("SELECT * from AuthDB WHERE Username = '$find_user'") or die(mysql_error()); 

and it worked not sure why but you can give it a try

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.