Vivid Lust Posted October 29, 2008 Share Posted October 29, 2008 Hey all! Ive got a page full of loads of checkboxes, and I only want the first 15 of them to be stored in some array. This is what ive done so far: (currently getting error: Fatal error: Maximum execution time of 30 seconds exceeded ) (checkbox page.... ) <?php $site[1] = $_POST['a']; $site[2] = $_POST['b']; $site[3] = $_POST['c']; $site[4] = $_POST['d']; $site[5] = $_POST['e']; $site[6] = $_POST['f']; $site[7] = $_POST['g']; $site[8] = $_POST['h']; $site[9] = $_POST['i']; $site[10] = $_POST['j']; $site[11] = $_POST['k']; $site[12] = $_POST['l']; $site[13] = $_POST['m']; $site[14] = $_POST['n']; $site[15] = $_POST['o']; //get 15 sites to add to database! $i = 0; $n = 1; while( $foo[15] !== "" ){ $i = $i + 1; if( $site[$i] != "" ){ $foo[$n] = $site[$i]; $n = $n + 1; }//if }//while ?> Thanks loads in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/ Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 looks like your while loop never exits. either $foo[15] start out === "" and then the loop doesn't even start, or it is !== "" forever... put a better condition in there. Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677271 Share on other sites More sharing options...
solon Posted October 29, 2008 Share Posted October 29, 2008 You had one extra '=' sign! Check it now it might works! <?php $site[1] = $_POST['a']; $site[2] = $_POST['b']; $site[3] = $_POST['c']; $site[4] = $_POST['d']; $site[5] = $_POST['e']; $site[6] = $_POST['f']; $site[7] = $_POST['g']; $site[8] = $_POST['h']; $site[9] = $_POST['i']; $site[10] = $_POST['j']; $site[11] = $_POST['k']; $site[12] = $_POST['l']; $site[13] = $_POST['m']; $site[14] = $_POST['n']; $site[15] = $_POST['o']; //get 15 sites to add to database! $i = 0; $n = 1; while( $foo[15] != "" ){ $i = $i + 1; if( $site[$i] != "" ){ $foo[$n] = $site[$i]; $n = $n + 1; }//if }//while ?> Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677289 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 @solon: thats actually a valid php operator. it checks for equality of type in addition to equality of content (because "" is also 0 and NULL in different contexts, but only "" is a string), and i think that checkboxes return strings so that should be ok. Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677297 Share on other sites More sharing options...
feidakila Posted October 29, 2008 Share Posted October 29, 2008 I also think that your loop is not correct. I guess that the $i could cause problems. If there are more than one $site[$i]=="" the value of $i will exceed the size of the array, going into an infinite loop. This may help but I would recode the loop $i = 0; $n = 1; while( $foo[15] != "" ){ if ($i<15) { $i = $i + 1; } else { $i=1; } if( $site[$i] != "" ){ $foo[$n] = $site[$i]; $n = $n + 1; }//if }//while Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677302 Share on other sites More sharing options...
Vivid Lust Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks alll, ive done this: <?php //get db and start session session_start(); require("../includes/db.php"); $max = "15"; $back = $_POST['bg']; $site[1] = $_POST['a']; $site[2] = $_POST['b']; $site[3] = $_POST['c']; $site[4] = $_POST['d']; $site[5] = $_POST['e']; $site[6] = $_POST['f']; $site[7] = $_POST['g']; $site[8] = $_POST['h']; $site[9] = $_POST['i']; $site[10] = $_POST['j']; $site[11] = $_POST['k']; $site[12] = $_POST['l']; $site[13] = $_POST['m']; $site[14] = $_POST['n']; $site[15] = $_POST['o']; //get 15 sites to add to database! $i = 0; $n = 1; while( $foo[15] != "" ){ if ($i<15) { $i = $i + 1; } else { $i=1; } if( $site[$i] != "" ){ $foo[$n] = $site[$i]; $n = $n + 1; }//if } // set some variables $user_pass = $_SESSION['user']; $user_email = $_SESSION['user2']; #$sql ="UPDATE users SET bg=\"$back\",search=\"$search\",social=\"$social\" WHERE email=\"$user_email\" AND pass=( \"$user_pass\" )"; #$query=mysql_query($sql, $link) #or die(mysql_error()); $o = 0; while($o <15){ $o = $o + 1; echo $foo[$o]; } ?> <link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" /> Done! Please refresh your page! But no values for $Foo[] is being echoed out... any ideas? Thanks! This might help: <input type="checkbox" name="a" value="http://www.cnn.com">CNN<br /> <input type="checkbox" name="b" value="http://www.bbc.com">BBC<br /> <input type="checkbox" name="c" value="http://www.nbc.com">NBC<br /> <input type="checkbox" name="d" value="http://www.abcnews.go.com">ABC News<br /> <input type="checkbox" name="e" value="http://www.usatoday.com">USA Today<br /> <input type="checkbox" name="f" value="http://www.msnbc.msn.com">MSNBC<br /> <input type="checkbox" name="g" value="http://www.nytimes.com">The New York Times<br /> <input type="checkbox" name="h" value="http://www.ajc.com">AJC<br /> <input type="checkbox" name="i" value="http://www.chicagotribune.com">Chicago Tribune<br /> <input type="checkbox" name="j" value="http://www.washingtonpost.com">Washington Post<br /> <input type="checkbox" name="k" value="http://www.chrone.com">Chrone<br /> <input type="checkbox" name="l" value="http://www.denverpost.com">Denver Post<br /> <input type="checkbox" name="m" value="http://www.knoxnews.com">Knox News<br /> <input type="checkbox" name="n" value="http://www.foxnews.com">Fox News<br /> <input type="checkbox" name="o" value="http://www.skynews.com">Sky News<br /> Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677370 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 i'm sorry, but your code ticked me off i'm not sure why your's didn't display anything, so here, think works: <?php //get db and start session session_start(); //require("../includes/db.php"); $max = "15"; //$back = $_POST['bg']; $back = $_POST['bg']; $site[1] = $_POST['a']; $site[2] = $_POST['b']; $site[3] = $_POST['c']; $site[4] = $_POST['d']; $site[5] = $_POST['e']; $site[6] = $_POST['f']; $site[7] = $_POST['g']; $site[8] = $_POST['h']; $site[9] = $_POST['i']; $site[10] = $_POST['j']; $site[11] = $_POST['k']; $site[12] = $_POST['l']; $site[13] = $_POST['m']; $site[14] = $_POST['n']; $site[15] = $_POST['o']; //get 15 sites to add to database! for($i = 1; $i <= $max; ++$i){ if ($site[$i] != ""){ $foo[$i] = $site[$i]; } } // set some variables $user_pass = $_SESSION['user']; $user_email = $_SESSION['user2']; #$sql ="UPDATE users SET bg=\"$back\",search=\"$search\",social=\"$social\" WHERE email=\"$user_email\" AND pass=( \"$user_pass\" )"; #$query=mysql_query($sql, $link) #or die(mysql_error()); for ($i = 1; $i <= $max; ++$i){ echo $foo[$i]; } ?> <link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" /> Done! Please refresh your page! if you get an error telling you that $foo is undefined (like i did at first ) just add $foo = array(); under the declaration of $max. Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677398 Share on other sites More sharing options...
sasa Posted October 29, 2008 Share Posted October 29, 2008 change names of ALL checkbox to name="url[]" and try to print_r($_POST['url']); Quote Link to comment https://forums.phpfreaks.com/topic/130551-solved-checkbox-help/#findComment-677407 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.