yddib Posted September 4, 2008 Share Posted September 4, 2008 <html> <head> </head> <body> <?php mysql_connect("localhost", "username ", "password") or die(mysql_error()); //connects to the databse mysql_select_db("username"); echo "open"; $result = @mysql_query("SELECT f_name FROM gradinfo where email ="[email protected]"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while($row = mysql_fetch_array($result)) { } ?> <form name="form" action="post.php" method="post"> First Name: <input type="text" name="f_name" value="<?php echo $row['f_name'] ?>"> <input type="submit" value="send"> <input type="reset" value="reset"> </form> </body> </html> Hi i'm having a small problem. I want to get the information out of the database and into the form. I think the problem lies with <?php echo $row['f_name']?> Can anyone help? Link to comment https://forums.phpfreaks.com/topic/122712-solved-info-from-database/ Share on other sites More sharing options...
pocobueno1388 Posted September 4, 2008 Share Posted September 4, 2008 You should be getting a syntax error from your query. change it to $result = mysql_query("SELECT f_name FROM gradinfo where email ='[email protected]'")or die(mysql_error()); What's the point of these lines? while($row = mysql_fetch_array($result)) { } Take that out and replace it with $row = mysql_fetch_array($result); Link to comment https://forums.phpfreaks.com/topic/122712-solved-info-from-database/#findComment-633714 Share on other sites More sharing options...
tmbrown Posted September 4, 2008 Share Posted September 4, 2008 Anytime you wish to output information from a query yo need to make sure when you call the row variable, that you do so inside the while braces "{}" <html> <head> </head> <body> <?php mysql_connect("localhost", "username ", "password") or die(mysql_error()); //connects to the databse mysql_select_db("username"); echo "open"; $result = @mysql_query("SELECT f_name FROM gradinfo where email ="[email protected]"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while($row = mysql_fetch_array($result)) { ?> <form name="form" action="post.php" method="post"> First Name: <input type="text" name="f_name" value="<?=$row['f_name'] ?>"> <input type="submit" value="send"> <input type="reset" value="reset"> </form> <?php } ?> </body> </html> or you can set the row array to a new variable array <html> <head> </head> <body> <?php mysql_connect("localhost", "username ", "password") or die(mysql_error()); //connects to the databse mysql_select_db("username"); echo "open"; $result = @mysql_query("SELECT f_name FROM gradinfo where email ="[email protected]"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } $yourvar = array(); while($row = mysql_fetch_array($result)) { $yourvar[] = $row; } ?> <form name="form" action="post.php" method="post"> First Name: <input type="text" name="f_name" value="<?=$yourvar['f_name'] ?>"> <input type="submit" value="send"> <input type="reset" value="reset"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/122712-solved-info-from-database/#findComment-633717 Share on other sites More sharing options...
tmbrown Posted September 4, 2008 Share Posted September 4, 2008 however the overall easiest way to do a query is: <?php //$mysqli = new mysqli("SERVER","USERNAME","PASSWORD","DATABASE"); $mysqli = new mysqli("localhost", "username ", "password","username"); $results = $mysqli->query("SELECT f_name FROM gradinfo where email ="[email protected]); $resultset = $results->fetch_assoc(); ?> Then you simply continue on your normal merry way. You output the same way you would as if you were using mysql procedural functions. Link to comment https://forums.phpfreaks.com/topic/122712-solved-info-from-database/#findComment-633719 Share on other sites More sharing options...
yddib Posted September 4, 2008 Author Share Posted September 4, 2008 Yaay it works thanks!! Link to comment https://forums.phpfreaks.com/topic/122712-solved-info-from-database/#findComment-633720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.