Looktrne Posted October 21, 2013 Share Posted October 21, 2013 I am transfering a site from PHP 5.2 to PHP 5.4 now the checkboxes are not being passed to PHP the html looks like this <form action="index.php?page=matchfinder&action=enable" method=post> <tr> <td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td> <td width=50%><input value=1 type=checkbox name=search_marital_status[2]> Married</td> <td width=50%><input value=1 type=checkbox name=search_marital_status[3] checked> Divorced</td> </tr> <input type="submit" value="Update Settings"> </form> on the PHP page that it posts to I don't receive the $search_marital_status data.if I change "search_marital_status[1]" to "search_marital_status1" it can read the variablemy question is why would this work normally on 5.2 but not 5.4?any suggestions it saves values into a database field names "marital_status" and would look like this if all 3 were checked "|1|3|"Why would this be broken in 5.4? any thoughts? it doesn't like the checkbox variables using [1] [2] on the endthanks for any insitePaul Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 (edited) Why do none of your checkboxes have different values? In the processing page, what does this output when the form is submitted echo '<pre>', print_r($_POST, 1), '</pre>'; Edited October 21, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 21, 2013 Share Posted October 21, 2013 How are you reading in the data submitted through the form? Perhaps the removal of "register_globals" has something to do with the issue: http://www.php.net/manual/en/migration54.incompatible.php Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 That's what I was wondering but they were deprecated over a decade ago Quote Link to comment Share on other sites More sharing options...
Looktrne Posted October 21, 2013 Author Share Posted October 21, 2013 Basically if all 3 are checked I would need:$search_marital_status = "|1|3|5|"; this is what I need to save into the database Quote Link to comment Share on other sites More sharing options...
Looktrne Posted October 21, 2013 Author Share Posted October 21, 2013 I believe it may be using register globals but have seen it work on sites with it disabled also I pretty much need a variable to equal$search_marital_status = "|1|3|5|"; if I selected all 3 boxesis there a simple way to re-write the buttons to accomplish this? thanksPaul Quote Link to comment Share on other sites More sharing options...
alpine Posted October 21, 2013 Share Posted October 21, 2013 Could you post the rest of index.php that handles the posted data.. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 21, 2013 Share Posted October 21, 2013 (edited) That is possible if your check boxes values are set, using <td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td> <td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td> <td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td> I assume 1 is Single 3 is Married 5 is Divorced To get the selected values separated by a pipe, you'd do $search_martial_status = implode('|', $_POST['search_martial_status']); Edited October 21, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 21, 2013 Share Posted October 21, 2013 First, I would recommend changing the values for your checkboxes. <td width=50%><input value=1 type=checkbox name=search_marital_status[] checked> Single - Never Married</td> <td width=50%><input value=3 type=checkbox name=search_marital_status[]> Married</td> <td width=50%><input value=5 type=checkbox name=search_marital_status[] checked> Divorced</td> When the form is submitted, you can loop through the $_POST['search_marital_status'] variable to get the values. Quote Link to comment Share on other sites More sharing options...
Looktrne Posted October 21, 2013 Author Share Posted October 21, 2013 Seems Register Globals OFF is okbut Safe_mode should be disabled according to the scriptI know Safe_mode is no longer existing.... any thoughts on how this may effect my Form? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 21, 2013 Share Posted October 21, 2013 Seems Register Globals OFF is ok but Safe_mode should be disabled according to the script I know Safe_mode is no longer existing.... any thoughts on how this may effect my Form? The form most likely isn't the problem. The problem more likely resides in the script which processes the form submission. If you're looking for answers, you'll need to post that code. Quote Link to comment Share on other sites More sharing options...
Looktrne Posted October 21, 2013 Author Share Posted October 21, 2013 The form most likely isn't the problem. The problem more likely resides in the script which processes the form submission. If you're looking for answers, you'll need to post that code. Here is the page that receives it... all it does is write the marital_status variable into the database. When I use a variable without [] or [1] in the button it passes the data with [] or [1] I get nothing... I just need a simple way to rewrite the button code so I can then write to database as |1|2|3 as explained above. thanks for any thoughts <? if($action == disable) { q("UPDATE dt_members SET matchfinder='0' WHERE id='$fMember[id]'"); $fMember[ matchfinder ] = 0; } if($action == enable) { $error = ""; if((int)$age_from <= 0 || (int)$age_to <= 0 || $age_from > $age_to || $age_to > 90) { $error = "Invalid age from and age to entered! Please try again."; } if($error == "") { q("UPDATE dt_members SET looking_for='$looking_for' WHERE id='$fMember[id]'"); q("UPDATE dt_members SET matchfinder='1' WHERE id='$fMember[id]'"); $fMember[ matchfinder ] = 1; $fMember[ looking_for ] = $looking_for; $f_mf = f(q("SELECT * FROM dt_matchfinder WHERE member_id='$fMember[id]'")); $fields = array( "search_marital_status", "search_body_type", "search_hair_color", "search_eye_color", "search_race", "search_religion", "search_education", "search_occupation", "search_food" ); foreach($fields as $field_name) { if(isset($$field_name)) { $temp = "|"; foreach($$field_name as $field_key=>$field_value) { if($field_value) $temp .= $field_key."|"; } $$field_name = $temp; } } if($f_mf == "") { q("INSERT INTO dt_matchfinder(member_id, age_from, age_to,country,race,marital_status,education,hair_color,eye_color,food,occupation,state,city) VALUES('$fMember[id]', '$age_from','$age_to','$search_country','$search_race','$search_marital_status','$search_education','$search_hair_color','$search_eye_color','$search_food','$search_occupation','$state','$city')"); } else { q("UPDATE dt_matchfinder SET age_from='$age_from' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET age_to='$age_to' WHERE id='$f_mf[id]'"); // new code for webDate v1.3.5 q("UPDATE dt_matchfinder SET country='$search_country' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET state='$state' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET city='$city' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET marital_status='$search_marital_status' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET body_type='$search_body_type' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET hair_color='$search_hair_color' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET eye_color='$search_eye_color' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET race='$search_race' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET religion='$search_religion' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET education='$search_education' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET occupation='$search_occupation' WHERE id='$f_mf[id]'"); q("UPDATE dt_matchfinder SET food='$search_food' WHERE id='$f_mf[id]'"); } } } $f_mf = f(q("SELECT * FROM dt_matchfinder WHERE member_id='$fMember[id]'")); if($f_mf != "" && $fMember[ matchfinder ] == 1) { $enabled = 1; } if($enabled) { $matchfinder_status = "enabled"; $matchfinder_submit = "Update Settings"; $matchfinder_disable = '<input type="button" value="'."Disable Matchfinder".'" OnClick="window.location.href='."'index.php?page=matchfinder&action=disable'".'">'; } else { $matchfinder_status = "disabled"; $matchfinder_submit = "Enable Matchfinder"; } if ($error) { $matchfinder_error = '<tr>'; $matchfinder_error .= '<td class="trtc" height="25" colspan="2"> '; $matchfinder_error .= '<font color=C00000>'.$error.'</font>'; $matchfinder_error .= '</td>'; $matchfinder_error .= '</tr>'; } $looking_for = $fMember[ looking_for ]; $matchfinder_looking_for = sysGetValSelect(looking_for, dt_genders); $age_from=$f_mf[ age_from ]; $matchfinder_age_from = sysGetNumberSelect(age_from, 18, 55, 0); $age_to=$f_mf[ age_to ]; if($age_to=="")$age_to=35; $matchfinder_age_to = sysGetNumberSelect(age_to, 18, 80, 0); $search_country=$f_mf[ country ]; $matchfinder_search_country = sysGetSelect(search_country, dt_countries,0,$search_country); $matchfinder_search_state = ""; if(!$no_state) { $state = $f_mf[ state ]; if($state_dropdown) { $matchfinder_search_state_select = sysGetValSelect(state, dt_states,0,$state); } else { $matchfinder_search_state_select = '<input type=text name=state value="'.$state.'">'; } $matchfinder_search_state = parseVariables("templates/matchfinder_state.html",0); } $matchfinder_search_city = $f_mf[ city ]; $temp = explode("|", $f_mf[marital_status]); $search_marital_status = ""; foreach($temp as $i) $search_marital_status[$i] = 1; $matchfinder_marital_status = sysGetCheckboxesMatchfinder("search_marital_status", "dt_marital_status",0); $temp = explode("|", $f_mf[body_type]); $search_body_type = ""; foreach($temp as $i) $search_body_type[$i] = 1; $matchfinder_body_types = sysGetCheckboxesMatchfinder("search_body_type", "dt_body_types",0); $temp = explode("|", $f_mf[hair_color]); $search_hair_color = ""; foreach($temp as $i) $search_hair_color[$i] = 1; $matchfinder_hair_colors = sysGetCheckboxesMatchfinder("search_hair_color", "dt_hair_colors",0); $search_eye_color = ""; $temp = explode("|", $f_mf[eye_color]); foreach($temp as $i) $search_eye_color[$i] = 1; $matchfinder_eye_colors = sysGetCheckboxesMatchfinder("search_eye_color", "dt_eye_colors",0); $search_race = ""; $temp = explode("|", $f_mf[race]); foreach($temp as $i) $search_race[$i] = 1; $matchfinder_race = sysGetCheckboxesMatchfinder("search_race", "dt_races",0); $search_religion = ""; $temp = explode("|", $f_mf[religion]); foreach($temp as $i) $search_religion[$i] = 1; $matchfinder_religion = sysGetCheckboxesMatchfinder("search_religion", "dt_religions",0); $search_education = ""; $temp = explode("|", $f_mf[education]); foreach($temp as $i) $search_education[$i] = 1; $matchfinder_education = sysGetCheckboxesMatchfinder("search_education", "dt_educations",0); $search_occupation = ""; $temp = explode("|", $f_mf[occupation]); foreach($temp as $i) $search_occupation[$i] = 1; $matchfinder_occupation = sysGetCheckboxesMatchfinder("search_occupation", "dt_occupations",0); $search_food = ""; $temp = explode("|", $f_mf[food]); foreach($temp as $i) $search_food[$i] = 1; $matchfinder_food = sysGetCheckboxesMatchfinder("search_food", "dt_food",0); parseVariables("templates/matchfinder.html"); ?> Paul Quote Link to comment Share on other sites More sharing options...
Looktrne Posted October 21, 2013 Author Share Posted October 21, 2013 That is possible if your check boxes values are set, using <td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td> <td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td> <td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td> I assume 1 is Single 3 is Married 5 is Divorced To get the selected values separated by a pipe, you'd do $search_martial_status = implode('|', $_POST['search_martial_status']); I tried this <td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td> <td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td> <td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td> $search_martial_status = implode('|', $_POST['search_martial_status']); echo "Marital Status Is:".$search_martial_status."<br>" I get nothing out? if I change search_marital_status[1] to search_marital_status then I would get data but it seems it won't eccept array? this is just weird it works on some servers and not others. is there a simple way to re-write? the code is old I just want to re-write this part Paul Quote Link to comment Share on other sites More sharing options...
alpine Posted October 21, 2013 Share Posted October 21, 2013 You need to declare from both post and get data in your case, you have been relying on register_globals = ON ! In your form, you have <form action="test.php?page=matchfinder&action=enable" method=post> In order to get "page" and "action" status : $page = $_GET['page']; $action = $_GET['action']; // now you can use them .... Then handle posted values from form foreach($_POST['search_marital_status'] as $key => $val){ $status[] = $key; // you need key from your form names -> name[val] thing } $search_martial_status = implode('|',$status); Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 21, 2013 Share Posted October 21, 2013 You need to start showing use your actual code, as we are currently guessing at what the problem is. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 21, 2013 Share Posted October 21, 2013 Here's another quick tip. If you're not doing so already, you should debug with errors on and being displayed. On the script which processes the form submission, try adding the following at the top: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted October 21, 2013 Share Posted October 21, 2013 You need to start showing use your actual code, as we are currently guessing at what the problem is. It looks like the OP posted the code in Reply 12. I don't see any references to $_POST or $_GET, so the removal of "register_globals" is likely the culprit. Quote Link to comment Share on other sites More sharing options...
Solution Looktrne Posted October 21, 2013 Author Solution Share Posted October 21, 2013 I found a function that was killing the check boxes this function was being called and killing checkboxes from working //$type_rs_to_register = array( "GET", "POST", "COOKIE", "FILES", "SESSION", "SERVER" ); if ( !get_magic_quotes_gpc( ) ) { foreach ( $type_rs_to_register as $type_r ) { if ( !( 0 < @count( ${ "_".$type_r } ) ) ) { continue; } while ( list( $key, $value ) = each( ${ "_".$type_r } ) ) { ${ "_".$type_r }[$key] = addslashes( $value ); } } } 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.