doforumda Posted April 10, 2009 Share Posted April 10, 2009 hi i have written a code through i want to select all the data from mysql database and display it in html table but when i run that code it displays following output ".$myRowRes["firstname"]." ".$myRowRes["lastname"]." ".$myRowRes["region"]." "; } echo ""; ?> how can i solve this problem? Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/ Share on other sites More sharing options...
ratcateme Posted April 10, 2009 Share Posted April 10, 2009 can we see the whole thing please. i am guessing you might have a ?> where it shouldn't be Scott. Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/#findComment-806065 Share on other sites More sharing options...
doforumda Posted April 10, 2009 Author Share Posted April 10, 2009 <? $db_connect = mysql_connect("localhost","username","password"); mysql_select_db("cs",$db_connect); $selectQuery = "select * from statusvalues order by lastname ASC"; $resultName = mysql_query($selectQuery); echo "<table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>Region</td> </tr>"; while($myRowRes = mysql_fetch_assoc($resultName)) { echo "<tr> <td>".$myRowRes["statVal_id"]."</td> <td>".$myRowRes["firstname"]."</td> <td>".$myRowRes["lastname"]."</td> <td>".$myRowRes["region"]."</td> </tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/#findComment-806080 Share on other sites More sharing options...
doforumda Posted April 10, 2009 Author Share Posted April 10, 2009 this is my whole code <?php $db_connect = mysql_connect("localhost","username","password"); mysql_select_db("cs",$db_connect); $table = "statusValues"; if(isset($function) && $function == "add") { echo "This is the value - $regionNumber<br>"; $sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')"; $exe_query = mysql_query($sql_query); } $sql_reg = "select * from region"; $sqlQuery = mysql_query($sql_reg); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="indexxx.php?function=add"> <p>First Name: <input type="text" name="fname" id="fname"> </p> <p>Last Name: <input type="text" name="lname" id="lname"> </p> <p>Select Region Number: <?php echo "<select name='regionNumber' id='regionNumber'>"; while($record = mysql_fetch_array($sqlQuery)) { echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>"; } echo "</select>"; ?> </p> <p>Enter SSN No Dashes: <input type="text" name="ssn" id="ssn"> </p> <p> <input type="submit" name="button" id="button" value="OK"> </p> </form> <? $selectQuery = "select * from statusvalues order by lastname ASC"; $resultName = mysql_query($selectQuery);// or die(mysql_error()); echo "<table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>Region</td> </tr>"; while($myRowRes = mysql_fetch_array($resultName)) { echo "<tr> <td>".$myRowRes["statVal_id"]."</td> <td>".$myRowRes["firstname"]."</td> <td>".$myRowRes["lastname"]."</td> <td>".$myRowRes["region"]."</td> </tr>"; } echo "</table>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/#findComment-806118 Share on other sites More sharing options...
Spike121 Posted April 10, 2009 Share Posted April 10, 2009 Don't forget to put [ code ] before and [ /code ] after your code please (without the spaces). From what I could see, this should work. You forgot the php after ? <?php $db_connect = mysql_connect("localhost","username","password"); mysql_select_db("cs",$db_connect); $table = "statusValues"; if(isset($function) && $function == "add") { echo "This is the value - $regionNumber<br>"; $sql_query = "insert into statusvalues (firstname,lastname,region,ssn) values ('".$fname."','".$lname."','".$regionNumber."','".$ssn."')"; $exe_query = mysql_query($sql_query); } $sql_reg = "select * from region"; $sqlQuery = mysql_query($sql_reg); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="indexxx.php?function=add"> <p>First Name: <input type="text" name="fname" id="fname"> </p> <p>Last Name: <input type="text" name="lname" id="lname"> </p> <p>Select Region Number: <?php echo "<select name='regionNumber' id='regionNumber'>"; while($record = mysql_fetch_array($sqlQuery)) { echo "<option value = '".$record['regionNumber']."'>".$record['regionNumber']."-".$record['regionName']."</option>"; } echo "</select>"; ?> </p> <p>Enter SSN No Dashes: <input type="text" name="ssn" id="ssn" /> </p> <p> <input type="submit" name="button" id="button" value="OK" /> </p> </form> <?php // Edited here. Don't forget the "php" after the question mark. $selectQuery = "select * from statusvalues order by lastname ASC"; $resultName = mysql_query($selectQuery);// or die(mysql_error()); echo "<table width='400' border='1' cellspacing='0' cellpadding='0'> <tr> <td>ID</td> <td>First Name</td> <td>Last Name</td> <td>Region</td> </tr>"; while($myRowRes = mysql_fetch_array($resultName)) { echo "<tr> <td>".$myRowRes["statVal_id"]."</td> <td>".$myRowRes["firstname"]."</td> <td>".$myRowRes["lastname"]."</td> <td>".$myRowRes["region"]."</td> </tr>"; } echo "</table>"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/#findComment-806146 Share on other sites More sharing options...
doforumda Posted April 10, 2009 Author Share Posted April 10, 2009 thanks spike 121 it works Quote Link to comment https://forums.phpfreaks.com/topic/153422-need-help-in-retrieving-data-from-database/#findComment-806154 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.