Hangston Posted May 15, 2010 Share Posted May 15, 2010 Hi All, I have the following option, which is generated multiple times in a form using the contents of a database to create each line. The user then has the ability to go in and choose a frequency for each line. <td><select name="assisted_frequency[<?php echo $i; ?>]"> <option value="Monthly"<?php if (!(strcmp(Monthly, ""))) {echo "SELECTED";} ?>>Monthly</option> <option value="Weekly"<?php if (!(strcmp(Weekly, ""))) {echo "SELECTED";} ?>>Weekly</option> <option value="Daily"<?php if (!(strcmp(Daily, ""))) {echo "SELECTED";} ?>>Daily</option> <option value="Hourly"<?php if (!(strcmp(Hourly, ""))) {echo "SELECTED";} ?>>Hourly</option> <option value="One-Time"<?php if (!(strcmp(One-Time, ""))) {echo "SELECTED";} ?>>One-Time</option> </select> </td> I want to upload the user's frequencies into another database, but when I view the contents of the $_POST['assisted_frequency[5]'], I just see "Array" and a NULL value if this is inserted into the database. Does anyone know why this would not take the default value of "Monthly," or whatever the user chooses for that particular line, as it appears on the website? I'm using the following to view the contents of the option: assisted_frequency. (for testing purposes) <?php $freq[0] = $_POST['assisted_frequency[0]']; echo $freq; ?> The query I'm running is based on: <?php // query&db information for($i = 0; $i <= $expected; $i ++) { GetSQLValueString($_POST['assisted_frequency[$i]'], "text")); } Any help would be greatly appreciated! Thank you! Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/ Share on other sites More sharing options...
TeddyKiller Posted May 15, 2010 Share Posted May 15, 2010 May I ask why you have.. <select name="assisted_frequency[<?php echo $i; ?>] ... Whats the advantage of the [$i;] because thats now considered as an indexed array. If it's a unique ID. Just do.. <select name="assisted_frequency-<?php echo $i; ?> ... Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/#findComment-1058878 Share on other sites More sharing options...
Hangston Posted May 15, 2010 Author Share Posted May 15, 2010 Hi TeddyKiller, The short answer is: I'm a Noob. I have changed all of the assisted_frequency[$i] to assisted_frequency_<php echo $i; ?> in the form as you suggested. Updates also made in the insert query. This is showing up as expected in the page source, but is still uploading NULL values into the database on submit. Can you think of another reason why the option chosen would not be passed through? I really appreciate your help! Thank you. Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/#findComment-1058883 Share on other sites More sharing options...
Hangston Posted May 15, 2010 Author Share Posted May 15, 2010 Looks like the issue is in the following: GetSQLValueString($_POST['assisted_frequency_ $i'], "text")); When I put in a value, such as: GetSQLValueString($_POST['assisted_frequency_0'], "text")); The upload to the database works fine. Do you know the proper way to code this $_POST, to work with the increasing $i? The database uploads with a query, row by row, with: for($i = 0; $i <= $expected; $i++) { // db and sql statement GetSQLValueString($_POST['assisted_frequency_$i'], "text")); } Any ideas? Thank you! Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/#findComment-1058888 Share on other sites More sharing options...
Hangston Posted May 15, 2010 Author Share Posted May 15, 2010 Got it!! Just took some trial and error. GetSQLValueString($_POST['assisted_frequency_'.$i], "text") Thanks for gearing me in the right direction! Hangston Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/#findComment-1058889 Share on other sites More sharing options...
Pikachu2000 Posted May 15, 2010 Share Posted May 15, 2010 Put a print_r($_POST); in there somewhere after the form is submitted to see what form your $_POST array has taken. That should give you a better idea of how to access the values, or if they are even being passed. Link to comment https://forums.phpfreaks.com/topic/201890-_post-for-option-only-returns-array-when-echod-and-null-in-database/#findComment-1058893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.