Jump to content

[SOLVED] getting the word "array" not the value


dolcezza

Recommended Posts

Can someone help me get the names "hotel" or whatever when checked...I am getting the word "array"

Help for a newbie... greatly appreciated.

 

<input type="text" size="15" name="travelexp" id="travelexp">
       <input type="checkbox" name="travelinc[]" value="mileage">mileage <input type="checkbox" name="travelinc[]" value="flight">flight <input type="checkbox" name="travelinc[]" value="hotel">hotel <input type="checkbox" name="travelinc[]" value="perdiem">per diem</p>

 

$travelinc = ($_POST['travelinc']);
$how_many = count($travelinc);
	if ($how_many>0) {
	$travelinc = 'N/A';
        }
        for ($i=0; $i<$how_many; $i++) {
			$pdf->MultiCell(0,5, $travelinc . ", ",0,0);
        } 

the word "array" is in the database... this shouldn't be, right?

It must be the way it is going in?

$query = "UPDATE events SET address='$address', city='$city', state='$state', zip='$zip', directions='$directions', honorarium='$honorarium', travelexp='$travelinc', sig='$sig', other='$eventnotes' WHERE eventid = '$eventid'";

it's coming from

<input type="checkbox" name="travelinc[]" value="mileage">mileage <input type="checkbox" name="travelinc[]" value="flight">flight <input type="checkbox" name="travelinc[]" value="hotel">hotel <input type="checkbox" name="travelinc[]" value="perdiem">per diem</p>

ok... someone over in mysql said to serialize it to put it into the database, no prob.

 

but I want to use it directly from the form.

The following code is almost there, it says "array mileage, travel"

how can I get rid of the word array?

foreach($_POST['travelinc']  as  $value)  {
$travelinc .= " $value, ";
} 

$travelinc = ($_POST['travelinc']);
$how_many = count($travelinc);
	if ($how_many>0) {
	$travelinc = 'N/A';
        }
        for ($i=0; $i<$how_many; $i++) {
			$pdf->MultiCell(0,5, $travelinc . ", ",0,0);
        } 

Why would you say $travelinc is equal to 'N/A' if $how_many is greater than 0? ???

 

If you want to get the array items as a string, I think you can just do this:

<?php
$travelinc = implode(",", $_POST['travelinc']);
?>

 

If you want to serialize it, you can.

foreach($_POST['travelinc']  as  $value)  {
$travelinc .= " $value, ";
} 

That could give you problems if you have register_globals on.

 

try

$user_travelinc_choices = implode(",",$_POST['travelinc']);

 

That will give you a comma separated string to insert into a db field.

 

 

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.