Jump to content

$_POST for option only returns "Array" when echo'd and NULL in database


Hangston

Recommended Posts

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!

 

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; ?> ...

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. 

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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.