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 Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/ Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 mysql_query(). Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384895 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? Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384898 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384901 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"; } Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384904 Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Do you have a field called data? Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384905 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384906 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. Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384908 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.""; Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384911 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 Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384912 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'"; Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384921 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"; } Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384926 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384941 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 Link to comment https://forums.phpfreaks.com/topic/76034-solved-request-data/#findComment-384947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.