Jump to content

Archived

This topic is now archived and is closed to further replies.

yuencr20

Multiple Checkbox values need to be stored

Recommended Posts

HELP,

I have an online Evaluation form where the info needs to be stored in a mysql DB. The only problem that I'm running into is that I have a few tables that there are multiple checkboxes, where the multiple values need to be stored in the same columb of that row. Right now it's just taking the last value entered and submiting that into the columb. Ex.. If the a person enters values {3,5,&7}..... I want {3,5,7} to show up in one row rather than just {7}. How can this be done? I am using an early version of both PHP Coder and Mysql just for general information.

 

Here is some html code of the table with multiple checkboxes:

<tr>

<td valign="top" height="205">

<blockquote>

<p>Do you work in any of the following places?<br>

<b>(check all that apply)</b></p>

</blockquote>

<table width="86%" border="0">

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="1">

</td>

<td width="54%">Community Health Center</td>

<td width="3%">

<input type="checkbox" name="following_places" value="8">

</td>

<td width="36%">Migrant Health Center </td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="2">

</td>

<td width="54%">Health Care for Homeless Center</td>

<td width="3%">

<input type="checkbox" name="following_places" value="9">

</td>

<td width="36%">Public Housing Primary Care Center</td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="3">

</td>

<td width="54%">Rural Health Clinic</td>

<td width="3%">

<input type="checkbox" name="following_places" value="10">

</td>

<td width="36%">Community Mental HEalth Center</td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="4">

</td>

<td width="54%">National Health Service Corps Site</td>

<td width="3%">

<input type="checkbox" name="following_places" value="11">

</td>

<td width="36%">Indian Health Services</td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="5">

</td>

<td width="54%">Federally-Qualified Health Center</td>

<td width="3%">

<input type="checkbox" name="following_places" value="12">

</td>

<td width="36%">State or Local Health Department</td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="6">

</td>

<td width="54%">Ambulatory Practice Sites Designated By Stae Governors</td>

<td width="3%">

<input type="checkbox" name="following_places" value="13">

</td>

<td width="36%">Public Health Hospital</td>

</tr>

<tr valign="top">

<td width="4%"> </td>

<td width="3%">

<input type="checkbox" name="following_places" value="7">

</td>

<td width="54%">HPSA (Federally Designated Health Proffesionals Storage

Area </td>

<td width="3%">  </td>

<td width="36%"> </td>

</tr>

</table>

</td>

</tr>

 

 

 

Here is the PHP code that stores all of the corresponding info into the DB:

 

 

 

<?

//PROCESS THE FORM//

 

$connection = mysql_connect ("localhost", "derek", "geradmin") or die ("Could not connect");

 

if ($connection){

//echo "Connected to database... <br>";

//echo "Processing data... <br>";

 

//SELECTING PROPER DATABASE AND TABLE

$dbname = "gerdbase";

$tableName = "test_eval";

$dbs = mysql_select_db ($dbname, $connection) or die ("Could not select database");

 

//*************************PROCESS DATA SENT TO PAGE**********************//

//RACE DATA

if ($race_other == ""){

$race_other = "null";

}

if ($race != "8"){

$race_other = "null";

}

 

//CITY AND COUNTY DATA

if ($w_city == ""){

$w_city = "null";

}

if ($w_county == ""){

$w_county = "null";

}

 

//EDUCATION DATA

if ($education_other == ""){

$education_other = "null";

}

if ($education != "6"){

$education_other = "null";

}

 

//DEGREES AND CERTIFICATES DATA

$d_cs = "";

if (sizeof($degrees_certs) < 5){

$extra = 5 - sizeof($degrees_certs);

$add = "";

for ($j = 0; $j < $extra; $j++){

$add .= "0_";

}

for ($i = 0; $i < sizeof($degrees_certs); $i++){

$d_cs .= "$degrees_certs[$i]_";

}

$d_cs .= "" . $add;

}

else {

for ($i = 0; $i < 5; $i++){

$d_cs .= "$degrees_certs[$i]_";

}

}

 

if ($degrees_certs_other == ""){

$degrees_certs_other = "null";

}

 

//FORMAL TRAINING DATA

$fty = array ('0', '0', '0', '0', '0', '0', '0', '0');

$fty_text = "";

if ((sizeof($formal_train_yes) == 0) || ($formal_train == "2")){

$fty_text = " _ _ _ _ _ _ _ _";

$formal_train_yes_other = "null";

}

else {

for ($i = 0; $i < sizeof($formal_train_yes); $i++){

$val = trim($formal_train_yes[$i]);

settype ($val, "integer");

$ind = $val - 1;

$fty[$ind] = '1';

}

for ($k = 0; $k < sizeof($fty); $k++){

$fty_text .= $fty[$k] . "_";

}

}

 

if ($formal_train_yes_other == "") {

$formal_train_yes_other = "null";

}

 

//DISCIPLINE/PROFESSION DATA

if (($dis_prof_other1 == "") && ($dis_prof_other2 == "") && ($dis_prof_other3 == "")){

$dis_prof_other = "null";

}

else {

if ($dis_prof_other1 != ""){

$dis_prof_other = $dis_prof_other1;

}

else {

if ($dis_prof_other2 != ""){

$dis_prof_other = $dis_prof_other2;

}

else {

if ($dis_prof_other3 != ""){

$dis_prof_other = $dis_prof_other3;

}

}

}

}//end else $dis

if (($dis_prof != "34") && ($dis_prof != "21") && ($dis_prof != "31")){

$dis_prof_other = "null";

}

 

//PLACE OF EMPLOYMENT DATA

if ($place_employ_o == ""){

$place_employ_o = "null";

}

if ($place_employ != "14"){

$place_employ_o = "null";

}

 

 

 

//*******************************END PROCESSING DATA TO PAGE**************************

 

/************FOR TESTING PURPOSES TO CHECK VALUES**************************

ECHO OUT VALUES BEING SUBMITTED

echo "Id: $id <br>";

echo "Date: $date <br>";

echo "Gender: $gender <br>";

echo "Age: $age <br>";

echo "Race: $race ($race_other)<br>";

echo "Work City: $w_city <br>";

echo "Work County: $w_county <br>";

echo "Work State: $w_state <br>";

echo "Place of Work: $following_places <br>";

echo "Education: $education ($education_other) <br>";

echo "Degrees/Certificates: $degree_certs ($degrees_certs_other) <br>";

echo "Formal Training: $formal_training <br>";

echo " Yes (string): $fty_text ($formal_train_yes_other) <br>";

echo "Discipline: $discipline ($discipline_other) <br>";

echo "Faculty Member: $faculty_member <br>";

echo "Place of Employment: $place_employ ($place_employ_o) <br>";

echo "Job Title: $job_title <br>";

echo "Primary Role: $primary_role ($primary_role_other) <br>";

echo "Older Adults: $older_adults <br>";

echo "Isolate People: $isolated_people <br>";

echo "Disadvantages: $disadvantages <br>";

echo "Minority: $minority <br>";

***********************************************************************/

 

//******************PUT VALUES INTO THE DATABASE******************

settype ($id, "integer"); settype ($gender, "integer"); settype ($age, "integer");

settype ($race, "integer"); settype ($following_places, "integer"); settype ($education, "integer");

settype ($degree_certs, "integer"); settype ($formal_training, "integer"); settype ($formal_train_yes, "integer");

settype ($discipline, "integer"); settype ($faculty_member, "integer"); settype ($place_employ, "integer");

settype ($primary_role, "integer"); settype ($older_adults, "integer"); settype ($isolated_people, "integer");

settype ($disadvantages, "integer"); settype ($minority, "integer");

$sql_insert = "INSERT INTO $tableName ";

$sql_insert .= "(id, date, gender, age, race, race_other, w_city, w_county, w_state, following_places, education, education_other, degree_certs, degrees_certs_other, formal_training, formal_train_yes, formal_train_yes_other, discipline, discipline_other, faculty_member, place_employ, place_employ_other, job_title, primary_role, primary_role_other, older_adults, isolated_people, disadvantages, minority)";

$sql_insert .= "VALUES (\"$id\", \"$date\", \"$gender\", \"$age\", \"$race\", \"$race_other\", \"$w_city\", \"$w_county\",";

$sql_insert .= "\"$w_state\", \"$following_places\", \"$education\", \"$education_other\", \"$degree_certs\",";

$sql_insert .= "\"$degrees_certs_other\", \"$formal_training\", \"$fty_text\", \"$formal_train_yes_other\",";

$sql_insert .= "\"$discipline\", \"$discipline_other\", \"$faculty_member\", \"$place_employ\",";

$sql_insert .= "\"$place_employ_o\", \"$job_title\", \"$primary_role\", \"$primary_role_other\", \"$older_adults\", \"$isolated_people\", \"$disadvantages\", \"$minority\")";

 

$result = mysql_query ($sql_insert,$connection) or die ("Couldn't execute query. The query string was: $sql_insert");

 

echo "<font size\"4\"><b>Thank you for taking the time to fill in the demographic<br>";

echo "Your data has been stored...Follow the link below to continue.<b></font><br>";

echo "<a href=\"http://www.sahp.vcu.edu/gerontology/index.html\"> Main page</a>";

}

 

else{

//DATABASE IS DOWN...FORWARD THEM TO THE SITE

echo "Oops!! DATABASE MUST BE DOWN";

}// end else --> database is down

 

?>

 

 

 

 

Can anyone help me?

 

 

 

 

Thanks

Share this post


Link to post
Share on other sites

×

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.