englishcodemonkey Posted July 13, 2008 Share Posted July 13, 2008 OK so i'm trying to retrieve data from my mysqli database and display in a drop down box. My database is shown below: Table structure for table hosta Field Type Null Default hosta_id int(11) Yes NULL hosta_name varchar(50) Yes hybridizer varchar(50) Yes NULL size varchar(10) Yes NULL description varchar(1000) Yes NULL price float(5,2) Yes NULL and my code i have so far is: <?php require_once('conn.php'); echo '<select name='hosta' id='hosta'> <option> -- select -- </option>'; $q = "SELECT hosta_name FROM hosta"; $r = mysqli_query($q, $dbc); while($row=mysqli_fetch_array($r, MYSQLI_ASSOC)){ echo '<option value="'.$row['hosta_name'].'">'.$row['hosta_name'].'</option>'; } echo '</select>'; ?> at the moment nothing is showing in my website frame?? Any ideas? Thanks guys Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 13, 2008 Share Posted July 13, 2008 The error is on the line that shows echo '<select name='hosta' id='hosta'> you need to either replace the single quotes around hosta with double quotes, or escape the single quotes with a backslash. By putting single quotes, you're basically ending the string at "=", putting some text that the compiler can't understand('hosta') then starting the string back again but with no echo, and then repeating. Backslashes are the key to having quotes within echo statements(and others) Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted July 13, 2008 Author Share Posted July 13, 2008 So creating the drop down box works!! But i need to be able to create a submit button so that once the name is selcted the form posts this information to 'desc.php'. This is my code now: <?php require_once('conn.php'); $q = "SELECT hosta_name FROM hosta WHERE hosta_name LIKE 'A%' ORDER BY hosta_name"; $r = @mysqli_query ($dbc, $q); if ($r) { echo '<select name="hosta" id="hosta"> <option><b> Select a Hosta </b></option>'; while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)) { echo ' <option value="'.$row['hosta_name'].'">'.$row['hosta_name'].'</option>'; } echo '</select>'; } ?> Any ideas? THANKS! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 13, 2008 Share Posted July 13, 2008 Well, when you have a form, there are 3 critical parts to successfully posting it. Action, method, and submit. You will need, before any form elements are displayed: <form action=PAGE.php method="POST"> method="GET" is also an option, but I'd only do it for something like a search page then you need <input type=submit value="Submit"> also, close the form with </form> It's not required if that's the only form on your page, but if you have 2 separate forms, you will need it so the browser(and processing page) can know which page to go to and which input elements to process. and the string in value can be whatever you want. There are other ways to display and edit the way submit buttons look and work, but I suggest getting your form to correctly submit before messing around any further with the way it looks. 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.