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']; } ?> Quote Link to comment 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> Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
revraz Posted February 27, 2008 Share Posted February 27, 2008 You need { } around your while loop. Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 27, 2008 Share Posted February 27, 2008 Your missing a command separator somewhere. Quote Link to comment 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> Quote Link to comment 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! 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.