Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-19-2008, 11:13 AM   #1
Registered: Jul 2006
Distribution: Slackware
Posts: 47

Rep: Reputation: 15
php not all POST variables coming through

first i'll say i am new to php
my script is not accepting all the POST variables i'm expecting in fact if i do an
or die("")
after a
$var = $_POST['var']
it will die
i promise that i have typed the name of the variables correctly (for at least one of the ones that isn't working. Only array member 0 - 12 and 14 receive values. here's the script, with the form the post was too big so if anyone actually wants to see it i'll post it up


function commaCare($string) {
        if (strpos($string, ",")) {
                return "\"".$string."\"";
        return $string;
$fh = fopen("HousingTable.txt", 'a') or die("can't open file");
$title =  $POST_['subject']; //Fall 2008/2009
$array[0] = $_POST['FirstName'];
$array[1] = $_POST['LastName'];
$array[2] = $_POST['RUID'];
$array[3] = $_POST['Email'];
$array[4] = $_POST['Phone'];
$array[5] = $_POST['Birthdate'];
$array[6] = $_POST['Gender'];
$array[7] = $_POST['Affiliation']; #A&S grad/under
$array[8] = $_POST['Applicant_Status_B']; #1st year, 2nd year
$array[9] = $_POST['Applicant_Status_C']; #New/Returning
$array[10] = $_POST['Contract'];
$array[11] = $_POST['MealOptionA'];
$array[12] = $_POST['MealOptionB'];
$array[13] = $_POST['RU Express']; //RU Express Amnt
$array[14] = $_POST['Option1'].",".$_POST['Option2'].",".$_POST['Option3'].",".$_POST['Option4'].",".$_POST['Option5'];
$array[15] = $_POST['Mailing Address'] or die("something strange is up");
$array[16] = $POST_['CityStateM'];
$array[17] = $POST_['Cell'];
$array[18] = $POST_['Applicant_Status_A']; //grad/under/transfer self titled
$array[19] = $POST_['Dec08 Grad']; //yes/no
if (strcmp($POST_['Part-Time Info'], "") == 0) $array[20] = $POST_['Part_Time Student'];
else $array[20] =  $POST_['Part_Time Student'].".  ".$POST_['Part-Time Info'];
$array[21] = $POST_['Contract 2'];
$array[22] = $POST_['Room Selection Preference'];
$array[23] = $POST_['Apartment Type'];
$array[24] = $POST_['Law/Grad Roomate Preferences'];
$array[25] = $POST_['Apt Before Roomates'];
$array[26] = $POST_['UG Floor Preference'];
$array[27] = $POST_['Undergraduate Roomates'];
$array[28] = $POST_['Studys in Room']; //make sure these are coming through even though no val
$array[29] = $POST_['Goes to Bed']; //same as last one
$array[30] = $POST_['Rises'];  //same as last one
$array[31] = $POST_['Neat Room'];
$array[32] = $POST_['Light Sleeper'];
$array[33] = $POST_['Computer_in_room'];
$array[34] = $POST_['Music_in_room'];
$array[35] = $POST_['Frequent Guests'];
$array[36] = $POST_['Smoker'];
$array[37] = $POST_['Special_Concerns'];
$array[38] = $POST_['Grad Cash']."\n";
while (strpos($array[14],",,")) {
        $array[14] = str_replace(",,", "", $array[14]);
        if (strcmp($array[14], ",") == 0) $array[14] = "";
        if (strcmp(substr($array[14][sizeof($array[14])]), ",") == 0) $array[14] = substr($array[14],sizeof($array[14] - 2));

for ($i = 0; $i < sizeof($array) - 1; $i++) {
        fwrite($fh, commaCare($array[$i]).",") or die("can't write to file");
        echo "array[".$i."]: ".$array[$i]."<br>";
fwrite($fh, commaCare($array[$i]).",") or die("can't write to file");
Old 06-19-2008, 11:51 AM   #2
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Don't think, that there is anything wrong with your php script.
Can you post your form anyway?
If possible, you can clear out irrelevant lines.
Or - if you generate your form with php - you can post the generated html code?

Old 06-19-2008, 11:57 AM   #3
Registered: Jul 2006
Distribution: Slackware
Posts: 47

Original Poster
Rep: Reputation: 15
Old 06-19-2008, 02:33 PM   #4
Registered: Aug 2004
Location: Ohio
Distribution: Debian, Slackware
Posts: 58

Rep: Reputation: 15
Your code claims to be XHTML 1.0 Transitional which it is not. Run your code through an XML validator next time.

You can't put spaces in name="" or id="" properties - that's why half of your values aren't going through. You should also end all of your singleton tags. ie:
<input type="text" name="abc" id="xyz" />
instead of:
<input type="text" name="abc" id="xyz">
/me Hates WYSIWYG editors a little more

Edit: Also, you need to use $_POST not $POST and not $POST_

Last edited by derzok; 06-19-2008 at 02:45 PM.
Old 06-19-2008, 04:30 PM   #5
Registered: Jul 2006
Distribution: Slackware
Posts: 47

Original Poster
Rep: Reputation: 15
thank you very much, i didn't make this form im just trying to update the cgi process
Old 06-19-2008, 05:24 PM   #6
Registered: Aug 2003
Distribution: Debian, Ubuntu
Posts: 188

Rep: Reputation: 30
Ho, must be either blind or drunken. ;-)
$array[1 to 12] work - no spaces in field name, and correct access to $_POST[].
array[13] does not work - space in field name
array[14] works
all remaining array do not work - incorrect access to $POST_[] (look at the underscore).

If you do a print_r($_POST), you see the correctly filled array. (I copied your form to my server and tested it.) All POSTed values are present. Funny thing, that php obviously does not work correctly with whitespaces in assiciative arrays... I never realized. Will go in this.

If you have no access to the form, you propably can iterate over $_POST with array_keys or similar.
Sorry for being little unspecific, but I am in little hurry at the moment...

Greets, Clemente


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 09:37 PM
Adding users with PHP (pass php variables to Expect script) Jayla Programming 1 10-20-2006 11:44 AM
PHP:Unable to post variables from html form to mysql database vikram_cvk Linux - Software 1 09-29-2004 04:01 PM
Where are my environment variables coming from? jrbiochem Linux - General 3 06-03-2004 12:18 PM
Post information not coming through PHP form. m3kgt Programming 5 04-02-2004 02:42 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration