Jump to content

Issue Pulling Info Based On Logged In User


Usarjjaco
 Share

Recommended Posts

Hey Guys,Back with another rookie question I'm sure. Got my login script working properly; however I'm trying to now access data information for a sepcific user. Here's what code I'm using:

session_start();$uname = $_SESSION['username']; $con = mysql_connect("localhost","username","pass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("theripti_jml5", $con);$result =("SELECT * FROM ranchers WHERE username=$uname");echo "<table border='1'><tr><th>Owner ID</th><th>RegNum</th><th>Breed</th></tr>";while($row = mysql_fetch_array($result)) {  echo "<tr>";  echo "<td>" . $row['ownerID'] . "</td>";  echo "<td>" . $row['regnum'] . "</td>";  echo "<td>" . $row['breed'] . "</td>";  echo "</tr>";}  echo "</table>";mysql_close($con);?>

It should bring up 2 results from the Table "ranchers" because of the query to pull all data with the signed in username.However I get this error:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home5/theripti/public_html/virtuarancher/myranch.phpI put the @ sign in front of the query and that loads the table without any data. Your help would be appreciated. Also worth noting: When I'm doing a query for something like "SELECT * from ranchers" it works fine; but when I try to link it with the sessions user it gives me the error.Thanks in advance guys,JJ

Edited by usarjjaco
Link to comment
Share on other sites

$result =("SELECT * FROM ranchers WHERE username=$uname");When MySQL gets the query, it should be formed like this:SELECT * FROM ranchers WHERE username='xxx'
Ok; when I perform the line$result =(SELECT * From ranchers WHERE username='$uname');I get the error:Parse error: syntax error, unexpected T_STRING in /home5/theripti/public_html/virtuarancher/myranch.php on line 15=/I feel ridiculous not having a clue here .. but thanks for your help :)
Link to comment
Share on other sites

You still need double quotes around the entire query, the query is a string. The value for the username field in the query needs single quotes around it.
Ok got past that error; and got one last thing holding me up:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home5/theripti/public_html/virtuarancher/myranch.php on line 24That line of code is:while($row = mysql_fetch_array($result))
Link to comment
Share on other sites

Its looking for a resource. The way you have it set up $result is a string, not a resource. Your query line should look like this:$result = mysql_query("SELECT * FROM ranchers WHERE username='$uname'");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...