ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Code:
or die("")
after a
Code:
$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
SCIPT:
Code:
<?php
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");
fclose($fh);
?>
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?
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:
Code:
<input type="text" name="abc" id="xyz" />
instead of:
Code:
<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_
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.