denoteone Posted December 12, 2008 Share Posted December 12, 2008 this questions would fall under both forums. I think... I am writing a php page that shows data from a DB after the user selects and option from a drop down. here is what I have so far any help would be awesome this is my first time writing a page of this kind. <? echo " <html> <head> "; include 'connect.php'; if(isset($_POST["button"])) { // This is where I am haiving issues I think. $result = mysql_query("SELECT * FROM example WHERE name='$_POST['mydropdown']'") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; }else{ ?> </head> <body> <form action="<?=$_SERVER['PHP_SELF']?>" method="POST"> <select name="mydropdown"> <option value="docrequest">Document downloads</option> <option value="contactrequest">Contact Request</option> <option value="mediarequest">Media Info</option> </select> <input type="submit" value="Submit" border="0" name="button"> </form> </body> </html> <? } ?> Link to comment https://forums.phpfreaks.com/topic/136686-solved-php-get-data-from-mysql/ Share on other sites More sharing options...
priti Posted December 12, 2008 Share Posted December 12, 2008 where you got stucked ?? Link to comment https://forums.phpfreaks.com/topic/136686-solved-php-get-data-from-mysql/#findComment-713729 Share on other sites More sharing options...
dmccabe Posted December 12, 2008 Share Posted December 12, 2008 Try: $dropdown = $_POST['mydropdown']; $result = mysql_query("SELECT * FROM `example` WHERE `name`= '$dropdown' ") Also you should really use <?php not <? as some servers really dont like it[/code] Link to comment https://forums.phpfreaks.com/topic/136686-solved-php-get-data-from-mysql/#findComment-713732 Share on other sites More sharing options...
denoteone Posted December 12, 2008 Author Share Posted December 12, 2008 First question. if I am getting "Notice: Undefined variable: dropdown in /var/www/html/FORMDBINFO.php on line 13" does that mean my errors are turned on in my php.ini file? Because i though I set them to off? Link to comment https://forums.phpfreaks.com/topic/136686-solved-php-get-data-from-mysql/#findComment-713738 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2008 Share Posted December 12, 2008 There are a few things I see wrong with this. First of all you should not use short open tags "<?" you should use "<?php" because it is more universal. Try this code: <html> <head> <?php include("connect.php"); if(isset($_POST['button'])) { //make the query $query = "SELECT * FROM example WHERE name='" . $_POST['mydropdown'] ."'"; //get the results $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; } else{ ?> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="Post"> <select name="mydropdown"> <option value="docrequest">Document downloads</option> <option value="contactrequest">Contact Request</option> <option value="mediarequest">Media Info</option> </select> <input type="submit" value="Submit" border="0" name="button"> </form> </body> </html> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/136686-solved-php-get-data-from-mysql/#findComment-713743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.