burge124 Posted February 27, 2008 Share Posted February 27, 2008 hi, how can i echo the results of this query into the *** positions outside of the query? thanks <form name="form1" method="post" action=""> <label>username; **********<br> current password; </label> **********<br> <p> <label></label> current email; **********</p> </form> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("questiondb", $con); $result = mysql_query("SELECT * FROM user WHERE UserName='admin'"); while($row = mysql_fetch_array($result)) { echo $row['UserName']; echo $row['Password']; echo $row['Email']; } ?> Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/ Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 you can't...query has to come first: <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("questiondb", $con); $result = mysql_query("SELECT * FROM user WHERE UserName='admin'"); $user= mysql_fetch_array($result) echo $user['UserName']; echo $user['Password']; echo $user['Email']; ?> <form name="form1" method="post" action=""> <label>username; <?php echo $user['UserName']; ?> current password; </label> <?php echo $user['Password']; ?> <p> <label></label> current email; <?php echo $user['Email']; ?><p> </form> Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478065 Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 hi, it still doesnt work, heres the code i used.... and the output is below the code thanks <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("questiondb", $con); $result = mysql_query("SELECT * FROM user WHERE UserName='admin'"); while ($user= mysql_fetch_array($result)) echo $user['UserName']; echo $user['Password']; echo $user['Email']; ?> <form name="form1" method="post" action=""> <label>username; <?php echo $user['UserName']; ?> current password; </label> <?php echo $user['Password']; ?> <p> <label></label> current email; <?php echo $user['Email']; ?><p> </form> **************************************************************************************** admin username; current ; current email; admin username; current ; current email; Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478098 Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 You need { } around your while loop. Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478101 Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 Is UserName a unique field? So there is only one user named admin? In that case you don't need a while loop at all. Just run mysql_fetch_array once to get the first entry. Also, when you post code, please use the code button on the toolbar (it's the one with the # sign on it) Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478102 Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 keep getting this error message; Parse error: parse error, unexpected T_ECHO in C:\Program Files\EasyPHP 2.0b1\www\index.php on line 9 Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478113 Share on other sites More sharing options...
DarkerAngel Posted February 27, 2008 Share Posted February 27, 2008 Your missing a command separator somewhere. Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478116 Share on other sites More sharing options...
rhodesa Posted February 27, 2008 Share Posted February 27, 2008 use this: <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("questiondb", $con); $result = mysql_query("SELECT * FROM user WHERE UserName='admin'"); $user= mysql_fetch_array($result); ?> <form name="form1" method="post" action=""> <lable>Username:</label> <?php echo $user['UserName']; ?><br> <lable>Password:</label> <?php echo $user['Password']; ?><br> <lable>Email:</label> <?php echo $user['Email']; ?><br> </form> Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478123 Share on other sites More sharing options...
burge124 Posted February 27, 2008 Author Share Posted February 27, 2008 thats great thanks for your help! its been holding up my progress for ages! Link to comment https://forums.phpfreaks.com/topic/93333-echo-from-select-query/#findComment-478174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.