View Full Version : copied php form to new server - now it gives error codes?

09-04-2009, 02:26 AM
I am helping a nonprofit move their website to a new host - but I know nothing about php, which is what they use for their forms. I copied ALL the files off their old server onto a test folder on the new server, but the two forms on the new server do not work. (They are still working on the old server.)

Below are the error codes I get when I click submit. Am I missing something on the new server that needs to be there? Thank you!!

Warning: join() [function.join]: Invalid arguments passed in /home/lugec/public_html/mmm/submitform.php on line 87

Warning: join() [function.join]: Invalid arguments passed in /home/lugec/public_html/mmm/submitform.php on line 145

Warning: join() [function.join]: Invalid arguments passed in /home/lugec/public_html/mmm/submitform.php on line 147

Warning: Cannot modify header information - headers already sent by (output started at /home/lugec/public_html/mmm/submitform.php:87) in /home/lugec/public_html/mmm/submitform.php on line 172

09-04-2009, 02:52 AM
You're using the implode/join function improperly. The parameters expected are either a single array, or an array and glue (in either order, but I would definitely recommend using the $glue first and the $array second so it follows the same argument requirements as explode).
The header error will likely clear up once you fix you're join errors, from the looks of it its whining about the error tossed by the join.
This function hasn't changed in like 5 versions, and when it did it was to use an optional $glue. The only reason why it appears to have changes is that you've always had these errors but you're previous host suppressed them while you're new host does not.

09-04-2009, 02:52 AM
Can you post the code on those lines? Please.

But, my wild guess is that in your old server you had Register Globals ON and on the new server probably running PHP 5 has Register Globals OFF. Therefore your code does not work any more.

09-04-2009, 03:12 AM
Thank you for such fast replies! Here is the code on those lines (all the same):

$answer70 = join(", ", $_POST['answer70']);
$question71 = $_POST['question71'];
$answer71 = join(", ", $_POST['answer71']);
$question72 = $_POST['question72'];

Yes my new server is running php 5.2.9 -- and it does have register_globals Off

09-04-2009, 03:37 AM
Is answer70 been defined as an html input array?
As in, something like this:

<select name="answer70[]" multiple="multiple">
<option value="......


Implode/join requires an array for its second parameter.

09-04-2009, 03:54 AM
Yea you're definitely not passing an array through the function. To achieve what you want you could simply do:

$newLine = $_POST['answer1'] . ', ' . $_POST['question2'] . ', ';


Implode (the other name for join) takes an array and glues it together like a string.

Take this example, referring to what Fou-Lu was talking about

<form action = "<?php $_SERVER['php_self'] ?>" method = "post" >
<input type="text" name="a[]" />
<input type="text" name="a[]" />
<input type="text" name="a[]" />
<input type="text" name="a[]" />
<input type="text" name="a[]" />
<input type="submit" />


Here we are making $_POST into a multidimensional array, so the $_POST array, now holds a new enumerated array called 'a'

So if you're doing some sort of Q & A form, then all your inputs for answers could be something like name="answers[]" and all your questions could be like name="questions[]" and then you'd have two arrays, for answers and questions.

Then glue them like

$newanswerString = implode(', ', $_POST['answers']);
$newquestionString = implode(', ', $_POST['question']);

Very simble.

09-04-2009, 04:49 AM
Yes, its an input array, for questions that allows multiple selections for the answer. For example, one of the questions looks like this:

<input type="hidden" name="question70" value="How will your new dog spend its days">
<select name="answer70[]" size="4" multiple id="answer70">
<option value="Indoors">Indoors</option>
<option value="Crated">Crated</option>
<option value="Basement">Basement</option>

So how would I modify

$newLine = $_POST['answer1'] . ', ' . $_POST['question2'] . ', ';

for that?

You all are so great for helping, thank you!

09-04-2009, 07:37 AM
Thank you for pointing me in the right direction. I ended up switching to checkboxes, and using this:

$answer70 = implode(", ", $_POST['answer70']);
echo $answer70;

That only left me with the one header error msg, which I found a fix for by moving the header line from the bottom up to the very top.

I have a headache but I'm happy its all working now! THANK YOU!

09-04-2009, 11:56 AM
Wait, are you saying that join won't work but implode does? Curious. Very curious, considering join is just a synonym for implode.

09-04-2009, 09:13 PM
Maybe it was adding the echo lines and/or switching to checkbox instead of an option? I'll try just switching to checkboxes first when I work on the 2nd form (without changing it to implode) and will let you know!

-- ok first I tried adding the echo lines, that didn't fix it, then moved the header line to the top, still didn't work... but changed the word join to implode (without even changing to check boxes) and BINGO it worked!

Would have been a two minute fix had I known what I was doing.... might never have figured it out if it wasn't for this forum and your help. Thanks! :)