Jump to content

[SOLVED] Checkbox help


Vivid Lust

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 />
  

Link to comment
Share on other sites

i'm sorry, but your code ticked me off  :P;D

 

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.

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.