nshaw Posted December 30, 2014 Share Posted December 30, 2014 I've searched and found numerous examples for creating dynamic forms using PHP and MySQL; however, each seems to be different and I have been unsuccessful with all of them. What I get is an empty pulldown menu instead of the contents from the MySQL table. I've worked this till I'm blue in the face and am now turning to the forums for help. I'm developing/testing code in NetBeans 8.0.2. Here is my code (name of file is 'domains.php':<body><form method="post" action=""><select id="domain" name="domain"><?php// define connection variables$DBServer = "localhost"; // server name or IP address$DBUser = "xxxxxxxxx";$DBPass = "xxxxxxxxx";$DBName = "country";$DBPort = "3306"; // I include the port because I have two instances of MySQL - the other is 3309// create a connection to mysql$conn = mysqli_connect ($DBServer, $DBUser, $DBPass, $DBName, $DBPort);// check to see if a connection was made and, if yes, proceedif (mysqli_connect_errno()) { // connection failed echo "Database connection failed: " . mysqli_connect_error();}// the domain query to get all domain names$domainQuery = "select domains from domains_subdomains_cop";// run the query -- this works elsewhere to display the contents of a table$resultD = mysqli_query($conn, $domainQuery) or die ("Query to get data from domain failed: " . mysql_error());// with the exception of a pulldown menu, the while loop works well to display all records, etc.// I've seen examples with MYSQLI_ASSOC and without and I've tried both without success - I use it because I // haven't had any issues elsewhere in my programwhile ($row=mysql_fetch_array($resultD, MYSQLI_ASSOC)) { $domainName=$row[DOMAINS]; // DOMAINS is the table attribute I'm trying to pull echo "<option> $domainName // I accidentely put a ';' here once and that did show up in the pulldown menu </option>";}?></select></form></body>In advance, thank you for any help/insight you can provide!!!Nick. Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/ Share on other sites More sharing options...
mac_gyver Posted December 30, 2014 Share Posted December 30, 2014 you are using a mysql_fetch_array() statement with a mysqli_ database connection and query statement. you cannot mix mysql_ (no i) and mysqli_ (with an i) statements. if you had php's error_reporting set to E_ALL and display_errors set to ON, you would be getting an error at the mysql_fetch_array() statement alerting you to the mismatch. Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501223 Share on other sites More sharing options...
ginerjm Posted December 30, 2014 Share Posted December 30, 2014 Turn on PHP error checking (see my sign.) and you'll see a problem. You start out using myslqi functions but then you do a fetch with MySQL. Can't mix the two different interfaces. Stick with mysqlI. Also - remember that php is CASE_SENSITIVE!! You query for 'domains' but then you try and use an index called DOMAINS - which besides being in the wrong case should also be enclosed in quotes. Also your option tags don't have an 'value=' clauses in them. Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501224 Share on other sites More sharing options...
hansford Posted December 31, 2014 Share Posted December 31, 2014 In case you missed it - here's the sign: PS - If you're posting here you should be using: error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1');at the top of ALL php code while you develop it! Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501230 Share on other sites More sharing options...
ginerjm Posted December 31, 2014 Share Posted December 31, 2014 Doesn't my signature show up all the time? Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501231 Share on other sites More sharing options...
CroNiX Posted December 31, 2014 Share Posted December 31, 2014 Also $domainName=$row[DOMAINS]; 1) in your query you are retrieving "domains" (lowercase) 2) It should be $row['domains'], with quotes around the array index. Further, your <option> is wrong. The format should be: <option value="this-is-the-value-submitted-with-the-form">Text that is displayed in the dropdown</option> Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501233 Share on other sites More sharing options...
hansford Posted December 31, 2014 Share Posted December 31, 2014 Doesn't my signature show up all the time? It does, but not everybody might read it - it's grayed out and not the center of focus. Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501276 Share on other sites More sharing options...
Solution nshaw Posted December 31, 2014 Author Solution Share Posted December 31, 2014 Thank you, all! Yes, I was both mixing APIs and tenses (both corrected). It is now working!! Again, thank you! I pulled pieces of code from various places (obviously wrong). I'm now using only the mysqli APIs and have the APIs bookmarked. Quote Link to comment https://forums.phpfreaks.com/topic/293535-using-php-to-create-dynamic-forms/#findComment-1501324 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.