Jump to content

Issue Pulling Info Based On Logged In User


Usarjjaco

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

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

Archived

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

×
×
  • Create New...