dolcezza Posted January 15, 2008 Share Posted January 15, 2008 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); } Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/ Share on other sites More sharing options...
KrisNz Posted January 15, 2008 Share Posted January 15, 2008 try $pdf->MultiCell(0,5, $travelinc[$i] . ", ",0,0); Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440425 Share on other sites More sharing options...
dolcezza Posted January 15, 2008 Author Share Posted January 15, 2008 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440429 Share on other sites More sharing options...
tibberous Posted January 15, 2008 Share Posted January 15, 2008 Yeah. If it says Array in your database, you need to fix where you store it. Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440432 Share on other sites More sharing options...
dolcezza Posted January 15, 2008 Author Share Posted January 15, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440436 Share on other sites More sharing options...
dolcezza Posted January 16, 2008 Author Share Posted January 16, 2008 going to mysql forum.. since that is where the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440446 Share on other sites More sharing options...
dolcezza Posted January 16, 2008 Author Share Posted January 16, 2008 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, "; } Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440477 Share on other sites More sharing options...
Ken2k7 Posted January 16, 2008 Share Posted January 16, 2008 $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. Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440483 Share on other sites More sharing options...
KrisNz Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440484 Share on other sites More sharing options...
dolcezza Posted January 16, 2008 Author Share Posted January 16, 2008 thank you, I used this to put it in the database $travelincl = implode($_POST['travelinc'],","); and this to display it: foreach($_POST['travelinc'] as $value) { $travelincluded .= " $value, "; } Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440509 Share on other sites More sharing options...
Ken2k7 Posted January 16, 2008 Share Posted January 16, 2008 Well next time, read up on the functions. Quote Link to comment https://forums.phpfreaks.com/topic/86224-solved-getting-the-word-array-not-the-value/#findComment-440520 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.