winmastergames Posted February 5, 2008 Share Posted February 5, 2008 Well just to say this is different to my other post... Im trying to find a way to get data from a certain username only like email or something. The user will login and i need it to display their email address how do i go about trying to do this I tried in mysql just as a guess didnt work but i tried typing in mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); it just came up with nothing but i guess it will be something like that Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/ Share on other sites More sharing options...
Moon-Man.net Posted February 5, 2008 Share Posted February 5, 2008 Providing the data in the MySql database field `username` matches $username, this should work. Echo $username, and match it to the `username` field in the database. If they don't match, then there is your problem. if they do, then it is somewhere in your display code. Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459212 Share on other sites More sharing options...
PHP Monkeh Posted February 5, 2008 Share Posted February 5, 2008 Remove the ' ' around $username. You could use '{$username}' or just do: WHERE username = '".$username."' Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459214 Share on other sites More sharing options...
winmastergames Posted February 5, 2008 Author Share Posted February 5, 2008 It still doesnt show anything if i dont have WHERE username =....blah.blah stuff it shows the Data but when i do Where username =..blah.blah stuff..... it shows nothing?? what would be wrong i did Moon-Man.net post and everything was fine but does somehow the username and let say email do they have to be connected or something to be read?? Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459252 Share on other sites More sharing options...
Moon-Man.net Posted February 5, 2008 Share Posted February 5, 2008 can you please post the complete code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459257 Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 $email = mysql_query("SELECT email FROM users WHERE username = '" . $username . "''")or die(mysql_error()); $email = mysql_fetch_array($email); echo "email: " . $email[0]; This will only output the email for one user, so if more than one person has the same username, its not going to work. Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459263 Share on other sites More sharing options...
winmastergames Posted February 6, 2008 Author Share Posted February 6, 2008 Heres the complete code <?php //Defines Vars // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { $yrwebsite = $_POST["weburl"]; echo "Website Administration<p>"; if (isset($_COOKIE["ID_my_site"])) echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />"; else echo "Welcome guest!<br />"; echo "Your website URL is"; $sql = "SELECT * FROM users WHERE username = '$username'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<td>".$row['weburls']."</td><br>"; } echo "Your FTP Username is: "; $sql = "SELECT * FROM users"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<td>".$row['ftpuser']."</td>"; } echo "<br>"; echo "Your FTP Password is: "; $sql = "SELECT * FROM users"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<td>".$row['ftppass']."</td>"; } echo "<br><a href=logout.php>Logout</a>"; } } } else //if the cookie does not exist, they are taken to the login screen { header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459272 Share on other sites More sharing options...
Moon-Man.net Posted February 6, 2008 Share Posted February 6, 2008 Please try this <?php //Defines Vars // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])){ $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); while($info = mysql_fetch_array( $check )){ //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']){ header("Location: login.php"); }else{ $yrwebsite = $_POST["weburl"]; echo "Website Administration<p>"; if (isset($_COOKIE["ID_my_site"])){ echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />"; }else{ echo "Welcome guest!<br />"; } $sql = "SELECT * FROM users WHERE username = '$username'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<td>Your website URL is: ".$row['weburls']."</td>"; echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>"; echo "<td>Your FTP Password is: ".$row['ftppass']."</td>"; } echo "<br><a href=logout.php>Logout</a>"; echo "<br>"; echo "<br>DEBUG RESULT:" print_r(mysql_fetch_array($query)); } } }else{ //if the cookie does not exist, they are taken to the login screen header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459309 Share on other sites More sharing options...
winmastergames Posted February 6, 2008 Author Share Posted February 6, 2008 Tried it and this error comes up Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\userauthttt\members.php on line 36 Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459312 Share on other sites More sharing options...
Moon-Man.net Posted February 6, 2008 Share Posted February 6, 2008 My Mistake, forgot a ';' on line 35 <?php //Defines Vars // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])){ $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); while($info = mysql_fetch_array( $check )){ //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']){ header("Location: login.php"); }else{ $yrwebsite = $_POST["weburl"]; echo "Website Administration<p>"; if (isset($_COOKIE["ID_my_site"])){ echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />"; }else{ echo "Welcome guest!<br />"; } $sql = "SELECT * FROM users WHERE username = '$username'"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { echo "<td>Your website URL is: ".$row['weburls']."</td>"; echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>"; echo "<td>Your FTP Password is: ".$row['ftppass']."</td>"; } echo "<br><a href=logout.php>Logout</a>"; echo "<br>"; echo "<br>DEBUG RESULT:"; print_r(mysql_fetch_array($query)); } } }else{ //if the cookie does not exist, they are taken to the login screen header("Location: login.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459320 Share on other sites More sharing options...
winmastergames Posted February 6, 2008 Author Share Posted February 6, 2008 I tried it no errors but none of the information showed up heres what exactly came up Website Administration Welcome ttt to SWD Your website URL is: Your FTP Username is: Your FTP Password is: Logout DEBUG RESULT: Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459321 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Did you try my code? You don't need to select * from the database, that gives you way more than you need. You just need to select email. Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459325 Share on other sites More sharing options...
Moon-Man.net Posted February 6, 2008 Share Posted February 6, 2008 Haku, he is not trying to display the email at all, he wants the ftp username, ftp password and weburl for the specific user out of the database.... <?php //Defines Vars // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])){ $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); while($info = mysql_fetch_array( $check )){ //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']){ header("Location: login.php"); }else{ $yrwebsite = $_POST["weburl"]; echo "Website Administration<p>"; if (isset($_COOKIE["ID_my_site"])){ echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />"; }else{ echo "Welcome guest!<br />"; } $sql = "SELECT * FROM users"; $query = mysql_query($sql); $result=mysql_fetch_array($query); while($result as $row ) { echo "<td>Your website URL is: ".$row['weburls']."</td>"; echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>"; echo "<td>Your FTP Password is: ".$row['ftppass']."</td>"; } echo "<br><a href=logout.php>Logout</a>"; echo "<br>"; echo "<br>DEBUG RESULT:"; echo "Username: " .$username ."<br>"; print_r(mysql_fetch_array($query)); } } }else{ //if the cookie does not exist, they are taken to the login screen header("Location: login.php"); } ?> Let me know what that outputs, I'm guessing $username isnt being set correctly Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459356 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Really? Cause his first message said this: Im trying to find a way to get data from a certain username only like email or something. The user will login and i need it to display their email address how do i go about trying to do this Sure looks to me like he was looking to get the email address... Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459360 Share on other sites More sharing options...
Moon-Man.net Posted February 6, 2008 Share Posted February 6, 2008 Haku, I apologize, my mistake. I was judging what he wanted via the code, I must have misread his first post. Quote Link to comment https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/#findComment-459395 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.