implode function-error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
283Banfil
Forum Newbie
Posts: 7
Joined: Mon Sep 14, 2009 10:38 am

implode function-error?

Post by 283Banfil »

I have built a simple submit form, trying to understand how implode works. The form dumps the data to the database correctly, but gives me a error of
Warning: implode() [function.implode]: Invalid arguments passed in /
Can someone see what my problem may be. It works terrific, but I get the dang error. I have searched and tried everything. I'm not a php guru, so please explain fully!! THanks a ton.
It is telling me the error is on this line: $string = implode(', ', $user_email);
Also, I have used both POST and REQUEST with the same error returning

My code is this:

Code: Select all

<?php
$user_email = $_REQUEST['user_email'];
$string = implode(', ', $user_email);
$user_name = $_REQUEST['user_name'];
if (isset($_REQUEST['Submit'])) {
# INSERT THE DATA FROM THE FORM INTO MYSQL TABLE
$sql = "INSERT INTO $db_table(user_name,user_email) values ('$user_name','$string')";
if($result = mysql_query($sql ,$db)) {
echo '<h1>Thank you</h1>Your information has been entered into our database<br><br';
} else {
echo "ERROR: ".mysql_error();
}
} else {
?>
<h1>How To Use the Implode Function- trial, not working!</h1><hr>
<form method="post" action="">
  <p>Name:<br>
    <input name="user_name" type="text" size="30">
    <br>
Email: <br><input name="user_email[]" type="checkbox" id="user_email[]" value="red" /> 
  Red
<input name="user_email[]" type="checkbox" id="user_email[]" value="blue" /> 
Blue
<input name="user_email[]" type="checkbox" id="user_email[]" value="green" /> 
Green
<input name="user_email[]" type="checkbox" id="user_email[]" value="yellow" /> 
Yellow
<br>
    <input type="submit" name="Submit" value="Submit">
    </p>
  </form>
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: implode function-error?

Post by infolock »

More than likely it falls into your usage of $_REQUEST. Unless you actually set the form to be a REQUEST post method type, you're not going to have the data available. Try using $_POST instead of $_REQUEST (or $_GET if you're passing it via URL).
283Banfil
Forum Newbie
Posts: 7
Joined: Mon Sep 14, 2009 10:38 am

Re: implode function-error?

Post by 283Banfil »

I got it working. I had the code as

$user_email = $_REQUEST['user_email'];
$string = implode(', ', $user_email);
$user_name = $_REQUEST['user_name'];
if (isset($_REQUEST['Submit'])) {
Should have been:
if(isset($_REQUEST['Submit'])) {
$user_email = $_REQUEST['user_email'];
$string = implode(', ', $user_email);
$user_name = $_REQUEST['user_name'];
Thanks for looking. I've actually tried it with both REQUEST and POSt, and they both work. I am switching it to POST, as that's what I wanted anyways!!
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: implode function-error?

Post by infolock »

*smack head*. Yeah, $_REQUEST is $_POST, but it is also $_GET. It's basically both superglobals in 1. I don't use it though as I don't necessarily want to have the possibility of a $_GET variable overriding a $_POST value. Glad ya figured it out!
Post Reply