Jump to content

Check BOXES


phpapprentice

Recommended Posts

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]',

 

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

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)

?>

Link to comment
Share on other sites

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)
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.