librarygal Posted February 21, 2008 Share Posted February 21, 2008 I am trying to create a form that consists only of a pre-populated drop-down select box that will return the data associated with the user selection. I have only been doing PHP/MYSQL for a week and my html is minimal, so please forgive my ignorance. So far, I have the following code: <?php include"header.php"; ?> <form method="get" action="selectbox.php"> <select name="name"> <option value="Fluffy">Fluffy</option> <option value="Buffy">Buffy</option> <option value="Chirpy">Chirpy</option> <option value="Slim">Slim</option> <option value="Bowser">Bowser</option> <option value="Fang">Fang</option> <option value="Claws">Claws</option> <option value="Whistler">Whistler</option> </select> <input type="submit" value="Submit"><input type="reset"/> </form> <?php mysql_connect (localhost, schroed1_webuser, w3bUs3r); mysql_select_db (schroed1_menagerie); $sql = "SELECT * FROM event WHERE name LIKE '$name%'"; trigger_error("sql=$sql"); $result = mysql_query($sql) or die(mysql_error()); if ($row = mysql_fetch_array($result)) { do { print $row["name"]; print (" "); print $row["date"]; print (" "); print $row["type"]; print (" "); print $row["remark"]; print ("<p> "); } while($row = mysql_fetch_array($result)); } else {print "Sorry, no records were found!";} ?> <?php include "footer.php"; ?> Can someone please tell me what I'm doing wrong? Any help is much appreciated. Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Share Posted February 21, 2008 what error message are you getting? Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Share Posted February 21, 2008 try this: <? $mysqli = new mysqli('localhost','schroed1_webuser','w3bUs3r'); $mysqli->select_db('schroed1_menagerie'); $result = $mysqli->query("SELECT * FROM event WHERE name LIKE '$name%'"); echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}'</option>\n"; } echo "</select>\n"; $result->close(); ?> this is what im using although iv modified it with your particulars. this should just select your name option so you will have to do this for each. I to am a noob at this so apologies if it is completely wrong Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 I'm not receiving an error message, although there is a notice: Notice: sql=SELECT * FROM event WHERE name LIKE '%' When I select my name from the dropdown menu, it displays the entire contents of my db. Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks, Truck7758. I'll try that out. Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 this should just select your name option so you will have to do this for each. As I'm ridiculously new and unschooled with this, what exactly do you mean when you say I will have to do this for each? For each name? Do I need to insert the names into the code? Sorry, I am just not getting the hang of this yet. Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Share Posted February 21, 2008 for name, date, type and remark. Dont worry about it. i only started on thursday but with the help of this site iv created quite a good webbased order management system Keep going! Cheers, Mike Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 Do you mean like this? $sql = "SELECT * FROM event WHERE name LIKE '$name%'"; echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}'</option>\n"; } echo "</select>\n"; echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['date']}'</option>\n"; } echo "</select>\n"; $result->close(); echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['type']}'</option>\n"; } echo "</select>\n"; echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}'</option>\n"; } echo "</select>\n"; ?> Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 21, 2008 Share Posted February 21, 2008 for future posts.It is probably best not to post your database username and password etc... Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks, deansatch. I realized that after I posted and wasn't sure how to take it down. I'll remember next time. Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 21, 2008 Share Posted February 21, 2008 being a noob myself i dont know whether that would work or not altho i did it differently. on my page i have 4 dropdown menus and here if the code i used: <form method="post" action="<?php echo $PHP_SELF;?>"> <table> <tr> <th>Order Ref:</th> <td><input type='text' name='OrderRef' value='' size='10'></td> <th>Order ID:</th> <td><input type='text' name='OrderID' value='Will Auto Update' size='15'></td> </tr> </table> <table> <tr> <td align="center">Ordered By:</td> <td align="center">Authorised By:</td> <td align="center">Supplier:</td> <td align="center">Method Payment</td> </tr> <tr> <td> <? $mysqli = new mysqli('localhost','root','newr00t'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='user'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['userid']}'>{$row['name']}</option>\n"; } echo "</select>\n"; $result->close(); ?> </td> <td> <? $mysqli = new mysqli('localhost','root','newr00t'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM auth"); echo "<SELECT name='auth'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['authid']}'>{$row['name']}</option>\n"; } echo "</select>\n"; $result->close(); ?> </td> <td> <? $mysqli = new mysqli('localhost','root','newr00t'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM supplier"); echo "<SELECT name='supp'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['suppid']}'>{$row['name']}</option>\n"; } echo "</select>\n"; $result->close(); ?> </td> <td> <? $mysqli = new mysqli('localhost','root','newr00t'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM method"); echo "<SELECT name='method'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['method_id']}'>{$row['method']}</option>\n"; } echo "</select>\n"; $result->close(); ?> </td> </tr> </table> </form> Hope this helps Mike Quote Link to comment Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 Thanks, deansatch. I realized that after I posted and wasn't sure how to take it down. I'll remember next time. Click MODIFY at the upper right corner of your post. Good idea to take it down. Quote Link to comment Share on other sites More sharing options...
librarygal Posted February 21, 2008 Author Share Posted February 21, 2008 Not seeing the modify option... 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.