Jump to content

[SOLVED] sql query getting no data ?


runnerjp

Recommended Posts

hey im using this

 

<?php $query="SELECT * FROM users WHERE Username = '$_GET[username]' LIMIT 1"; 
$result=mysql_query($query); 
while($array=mysql_fetch_assoc($result)){
$pID=$array['ID'];
$puser=$array['username'];
}


?>


<?php echo $puser . " " . $ID;  ?>

to get a users data by following a link like mywebsite.com/members/name

 

where in the members folder i have

.htaccess

<?php RewriteEngine on
RewriteBase /
RewriteRule ^i([^/\.]+)/?$ /images.php?username=$1 
RewriteRule ^([^/\.]+)/?$ members/profile.php?username=$1 [L] ?>

 

shouldent $_GET[username] get it either form fact im logged in or from the url itself and display there information?

Link to comment
https://forums.phpfreaks.com/topic/78907-solved-sql-query-getting-no-data/
Share on other sites

Your rule should look more like....

 

RewriteRule ^members/([A-Za-z0-9]+)$ members/profile.php?username=$1

 

Then your code...

 

<?php

  if (isset($_GET['username'])) {
    $username = mysql_real_escape_string($_GET['username']);
    $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; 
    if ($result = mysql_query($query)) {
      if (mysql_num-rows($result)) { 
        $array = mysql_fetch_assoc($result);
        $pID = $array['ID'];
        $puser = $array['Username'];
      }
    }
  }

  echo $puser . " " . $pID;

?>

tried

 

<?php
if (isset($_GET['username'])) {
    $username = mysql_real_escape_string($_GET['username']);
    $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; 
    if ($result = mysql_query($query)) {
      if (mysql_num-rows($result)) { 
        $array = mysql_fetch_assoc($result);
        $pID = $array['ID'];
        $puser = $array['Username'];
     

  echo $puser . " " . $pID;
      
      } else {
        echo "No users found with id $id<br />";
      }
    } else {
      echo "Query failed<br />$sql<br />" . mysql_error();
    }
  } else {
    echo "No ID passed";
  }

  


?>

 

does this mean its not passing anyhting and if so why?

Try simplifying:

 

<?php
if (isset($_GET['username'])) 
{
    $username = $_GET['username'];
    $query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1";
    $result = mysql_query($query)

    if ($result)
    {
      if (mysql_num_rows($result)) 
      { 
        $array = mysql_fetch_assoc($result);
        $pID = $array['ID'];
        $puser = $array['Username'];
        echo $puser . " " . $pID;
       } 
      else {
        echo "No users found with id $id<br />";
      }
    } 
    else {
      echo "Query failed<br />$sql<br />" . mysql_error();
    }
} 
else {
    echo "No ID passed";
}
?>

 

You had at least 1 syntax error in the last block of code you posted.

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.