phpapprentice Posted October 24, 2008 Share Posted October 24, 2008 Need Help. I have three fielfd named StudentTeaching,InternTeaching,CredentialedTeacher. The form is working fine, when I check StudentTeaching, It will store TRUE on my StudentTeaching field and the rest FALSE. When I check InternTeaching, it will store TRUE on my InternTeaching field and the rest FALSE. But when I check them all, it will only store TRUE to the CredentialedTeacher field.which is the last field. What I want to do is if I check them all, it will store TRUE for all of the 3 fields need help. this is my form test.html ************* <input type="checkbox" name="status2" value="StudentTeaching" />Student Teaching <input type="checkbox" name="status2" value="InternTeaching"/>Intern Teaching <input type="checkbox" name="status2" value="CredentialedTeacher"/>Credentialed Teacher ************* this is some part of my add.php ********************* $stat2['StudentTeaching'] = 'false'; $stat2['InternTeaching'] = 'false'; $stat2['CredentialedTeacher'] = 'false'; $stat2[$_POST['status2']] = 'true'; ********************* ALSO part of my add.php ****************************** '$stat2[studentTeaching]','$stat2[internTeaching]','$stat2[CredentialedTeacher]', Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 change this: <input type="checkbox" name="status2" value="StudentTeaching" />Student Teaching <input type="checkbox" name="status2" value="InternTeaching"/>Intern Teaching <input type="checkbox" name="status2" value="CredentialedTeacher"/>Credentialed Teacher to <input type="checkbox" name="StudentTeaching" value="true" />Student Teaching <input type="checkbox" name="InternTeaching" value="true"/>Intern Teaching <input type="checkbox" name="CredentialedTeacher" value="true"/>Credentialed Teacher and change this block: $stat2['StudentTeaching'] = 'false'; $stat2['InternTeaching'] = 'false'; $stat2['CredentialedTeacher'] = 'false'; $stat2[$_POST['status2']] = 'true'; to $stat2['StudentTeaching'] = mysql_real_escape_string($_POST['StudentTeaching']); $stat2['InternTeaching'] = mysql_real_escape_string($_POST['InternTeaching']); $stat2['CredentialedTeacher'] = mysql_real_escape_string($_POST['CredentialedTeacher']); Quote Link to comment Share on other sites More sharing options...
phpapprentice Posted October 24, 2008 Author Share Posted October 24, 2008 It did not store anything in the fields Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 at the beginning of your PHP code that receives the POST, put this, run it, and post the output. it will give me an idea of what the POST data looks like: print '<pre>'.print_r($_POST,1).'</pre>';exit; Quote Link to comment Share on other sites More sharing options...
phpapprentice Posted October 24, 2008 Author Share Posted October 24, 2008 Array ( [FirstName] => John [LastName] => Doe [Address] => sadgasdg [City] => asgdasg [state] => Arkansa [ZipCode] => 14132 [HomePhone] => sadfasdf [WorkPhone] => asdfasdf [CellPhone] => asdfdasfs => asdfasdfas [EmergencyContactName] => sadfasdf [EmergencyContactPhone] => sadfasf [NoyceProgramAt] => sadfasdf [personnel] => K12Personnel [scholarReceivingFunding] => yes [major] => Science [sciencechoice] => Biology [status] => CredentialTeacher [school] => afsdfs [District] => asfdsadf [status2] => CredentialedTeacher [RoommateName] => ) Quote Link to comment Share on other sites More sharing options...
phpapprentice Posted October 24, 2008 Author Share Posted October 24, 2008 this is the second result, I CHECKED ALL THE BOXES. Array ( [FirstName] => dfgsdfgsdfg [LastName] => dsdfgsdfgsdf [Address] => sdfgsdfgsdf [City] => dfsgsdfg [state] => Alabama [ZipCode] => [HomePhone] => [WorkPhone] => [CellPhone] => => [EmergencyContactName] => [EmergencyContactPhone] => [NoyceProgramAt] => [personnel] => IHEpersonnel [scholarReceivingFunding] => yes [major] => Science [sciencechoice] => Biology [status] => Undergraduate [school] => wergasdfg [District] => adgsdfgsd [studentTeaching] => true [internTeaching] => true [CredentialedTeacher] => true [RoommateName] => ) Quote Link to comment Share on other sites More sharing options...
Barand Posted October 24, 2008 Share Posted October 24, 2008 only checked checboxes are posted, so $stat2['StudentTeaching'] = isset($_POST['StudentTeaching']) ? 'true' : 'false'; $stat2['InternTeaching'] = isset($_POST['InternTeaching']) ? 'true' : 'false'; $stat2['CredentialedTeacher'] = isset($_POST['CredentialedTeacher']) ? 'true' : 'false'; Quote Link to comment Share on other sites More sharing options...
phpapprentice Posted October 24, 2008 Author Share Posted October 24, 2008 barand, nothing was store in the 3 fields. the result is the same Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 everything is posting ok, can you post the code that receives the post and inserts it into the table? Quote Link to comment Share on other sites More sharing options...
phpapprentice Posted October 24, 2008 Author Share Posted October 24, 2008 when I check the the 3 boxes it will display TRUE for all with your code: print '<pre>'.print_r($_POST,1).'</pre>';exit; THIS IS WHAT I WANT TO DO: If I check StudentTeaching it must display TRUE to StudentTeaching and FALSE for the other fields - (InternTeaching, CredentialedTeacher). How can I do that? this is the code: <?php print '<pre>'.print_r($_POST,1).'</pre>';exit; $con = mysql_connect("localhost","mydatabase","mypassword"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("noyce", $con); //for field IHEpersonnel, K12Personnel, Scholar, $person['IHEpersonnel'] = 'false'; $person['K12Personnel'] = 'false'; $person['Scholar'] = 'false'; $person[$_POST['personnel']] = 'true'; //for field Mathematics, Science $maj['Mathematics'] = 'false'; $maj['Science'] = 'false'; $maj[$_POST['major']] = 'true'; //for field Biology,Chemistry,Geosciences, Physics $sci['Biology'] = 'false'; $sci['Chemistry'] = 'false'; $sci['Geosciences'] = 'false'; $sci['Physics'] = 'false'; $sci[$_POST['sciencechoice']] = 'true'; //for field Undergraduate, CredentialCandidate, CredentialTeacher //$stat['Undergraduate'] = 'false'; //$stat['CredentialCandidate'] = 'false'; //$stat['CredentialTeacher'] = 'false'; //$stat[$_POST['status']] = 'true'; //$stat2['Undergraduate'] = 'false'; //$stat2['CredentialCandidate'] = 'false'; //$stat2['CredentialTeacher'] = 'false'; //$stat2[$_POST['status']] = 'true'; //for field StudentTeaching, InternTeaching, CredentialedTeacher --THIS IS YOUR CODE $stat2['StudentTeaching'] = mysql_real_escape_string($_POST['StudentTeaching']); $stat2['InternTeaching'] = mysql_real_escape_string($_POST['InternTeaching']); $stat2['CredentialedTeacher'] = mysql_real_escape_string($_POST['CredentialedTeacher']); //$stat2['StudentTeaching'] = isset($_POST['StudentTeaching']) ? 'true' : 'false'; //$stat2['InternTeaching'] = isset($_POST['InternTeaching']) ? 'true' : 'false'; //$stat2['CredentialedTeacher'] = isset($_POST['CredentialedTeacher']) ? 'true' : 'false'; //for field FridayDinner $fri['FridayDinner'] = 'false'; $fri[$_POST['Friday']] = 'true'; $sql="INSERT INTO NoyceConferenceContact (FirstName, LastName, Address, City, State, ZipCode, HomePhone, WorkPhone, CellPhone, Email, EmergencyContactName, EmergencyContactPhone, NoyceProgramAt, IHEpersonnel, K12Personnel, Scholar, ScholarReceivingFunding, Mathematics, Science, Biology, Chemistry, Geosciences, Physics, Undergraduate, CredentialCandidate, CredentialTeacher, School, District, StudentTeaching, InternTeaching, CredentialedTeacher, FridayDinner ) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST[Address]','$_POST[City]','$_POST[state]','$_POST[ZipCode]','$_POST[HomePhone]','$_POST[WorkPhone]','$_POST[CellPhone]','$_POST', '$_POST[EmergencyContactName]','$_POST[EmergencyContactPhone]','$_POST[NoyceProgramAt]', '$person[iHEpersonnel]','$person[K12Personnel]','$person[scholar]', '$_POST[scholarReceivingFunding]', '$maj[Mathematics]','$maj[science]', '$sci[biology]','$sci[Chemistry]','$sci[Geosciences]','$sci[Physics]', '$stat[undergraduate]','$stat[CredentialCandidate]','$stat[CredentialTeacher]', '$_POST[school]','$_POST[District]', '$stat2[studentTeaching]','$stat2[internTeaching]','$stat2[CredentialedTeacher]', '$fri[FridayDinner]' )"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted October 24, 2008 Share Posted October 24, 2008 THIS IS WHAT I WANT TO DO: If I check StudentTeaching it must display TRUE to StudentTeaching and FALSE for the other fields - (InternTeaching, CredentialedTeacher). How can I do that? Sounds like you want radio buttons, not checkboxes Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 24, 2008 Share Posted October 24, 2008 and Barand's code didn't work? <?php $con = mysql_connect("localhost","mydatabase","mypassword"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("noyce", $con); //for field IHEpersonnel, K12Personnel, Scholar, $person['IHEpersonnel'] = 'false'; $person['K12Personnel'] = 'false'; $person['Scholar'] = 'false'; $person[$_POST['personnel']] = 'true'; //for field Mathematics, Science $maj['Mathematics'] = 'false'; $maj['Science'] = 'false'; $maj[$_POST['major']] = 'true'; //for field Biology,Chemistry,Geosciences, Physics $sci['Biology'] = 'false'; $sci['Chemistry'] = 'false'; $sci['Geosciences'] = 'false'; $sci['Physics'] = 'false'; $sci[$_POST['sciencechoice']] = 'true'; $stat2['StudentTeaching'] = isset($_POST['StudentTeaching']) ? 'true' : 'false'; $stat2['InternTeaching'] = isset($_POST['InternTeaching']) ? 'true' : 'false'; $stat2['CredentialedTeacher'] = isset($_POST['CredentialedTeacher']) ? 'true' : 'false'; //for field FridayDinner $fri['FridayDinner'] = 'false'; $fri[$_POST['Friday']] = 'true'; $sql="INSERT INTO NoyceConferenceContact (FirstName, LastName, Address, City, State, ZipCode, HomePhone, WorkPhone, CellPhone, Email, EmergencyContactName, EmergencyContactPhone, NoyceProgramAt, IHEpersonnel, K12Personnel, Scholar, ScholarReceivingFunding, Mathematics, Science, Biology, Chemistry, Geosciences, Physics, Undergraduate, CredentialCandidate, CredentialTeacher, School, District, StudentTeaching, InternTeaching, CredentialedTeacher, FridayDinner ) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST[Address]','$_POST[City]','$_POST[state]','$_POST[ZipCode]','$_POST[HomePhone]','$_POST[WorkPhone]','$_POST[CellPhone]','$_POST[Email]', '$_POST[EmergencyContactName]','$_POST[EmergencyContactPhone]','$_POST[NoyceProgramAt]', '$person[iHEpersonnel]','$person[K12Personnel]','$person[scholar]', '$_POST[scholarReceivingFunding]', '$maj[Mathematics]','$maj[science]', '$sci[biology]','$sci[Chemistry]','$sci[Geosciences]','$sci[Physics]', '$stat[undergraduate]','$stat[CredentialCandidate]','$stat[CredentialTeacher]', '$_POST[school]','$_POST[District]', '$stat2[studentTeaching]','$stat2[internTeaching]','$stat2[CredentialedTeacher]', '$fri[FridayDinner]' )"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?> Quote Link to comment 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.