Jump to content

nshaw

New Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by nshaw

  1. Well then, I'm 4 posts away... Again, thanks to all for your help! I couldn't have done it without you and, in the future, I will remember to bound my code properly with tags (thanks to whoever did it for me).
  2. Thank you, mac_gyver! Your post helped me solve the problem (there were a couple). I changed 'post' to 'get' and inside the function subdomains, I created a variable called $value = $_REQUEST['domain']. This returns the numeric value of each domain so I created a quick conversion to the proper string and all works! I also stopped passing a variable to the function and, instead, created an empty string variable called $domains. Again, I want to thank everyone for their help and assistance - I couldn't have done it without your help. Now, one quick question - I'm signed in but I cannot select the 'Like This' button, ever. Why is that? I'd like to give credit to those who have helped me. Best Regards!
  3. I'm using the NetBeans IDE v.8.0.2 and it has errors on by default. If I make an error in my code, it shows me where the error is and says what the error is. Right now, I'm not getting any errors; however, changing the format of my array did solve the problem of an empty pulldown list. THANK YOU! Once I get the function to accept the user input from the first pulldown menu then I'm set! :-) Again - thank you!
  4. Thank you, ginergm, My apologies for not wrapping my code using proper tags. I'll try your PS for php error checking. The format I'm using for my array is from an older book so it may be an issue; I'll change it and see what happens. Thank you!
  5. I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me: <!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html> Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards!
  6. 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.
  7. 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, proceed if (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 program while ($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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.