Ads Posted November 5, 2007 Share Posted November 5, 2007 I am haveing a realy bad day with PHp, I aplogise Here is My problem I want to request A Row of Data from a Table in the Data base? how do i do this Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 mysql_query(). Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 mysql_query(). Could you Elberate any further on that? Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 A simple example. <?php $sql = "SELECT data FROM foo WHERE id = 1 LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['data'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 A simple example. <?php $sql = "SELECT data FROM foo WHERE id = 1 LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['data'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } ?> Query failed Unknown column 'data' in 'field list' SELECT data FROM players WHERE id = 1 LIMIT 1 Thats the Error $sql = "SELECT data FROM players WHERE id = 1 LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['username'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Do you have a field called data? Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 You might want..... <?php $sql = "SELECT username FROM players WHERE id = 1 LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['username'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 This is the New error i get: Query failed You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 SELECT username FROM players WHERE email = $email = $_SESSION['email']; $sql = "SELECT username FROM players WHERE email = $email"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['username'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } What i am trying to do is get the Persons Name to Be displayed By Finding there Email. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 5, 2007 Share Posted November 5, 2007 $sql = "SELECT username FROM players WHERE email = ".$email.""; Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 n~ link=topic=166371.msg732433#msg732433 date=1194257672] $sql = "SELECT username FROM players WHERE email = ".$email.""; Same error still Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Use.... $sql = "SELECT username FROM players WHERE email = '$email'"; Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 Cool thanx, BUT, now it says That there are no results found? But there should be. heres the code. $email = $_SESSION['email']; $sql = "SELECT username FROM players WHERE email = '$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['username'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 The results don't lie. Have you got a call to session_start() prior to using the $_SESSION array? Also, try trimming the email of any extra whitespace. <?php session_start(); $email = trim($_SESSION['email']); $sql = "SELECT username FROM players WHERE email = '$email'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $row['username'] . "<br />"; } else { echo "No results found"; } } else { echo "Query failed<br />" . mysql_error() . "<br />$sql"; } ?> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 5, 2007 Author Share Posted November 5, 2007 Thank You, That Fixed it Now Lots more Erros to Fix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.