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
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;

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.