[KLUG Members] php 4.3.10, correction

bill bill at billtron.com
Sat Jan 29 11:09:38 EST 2005


On Sat, 2005-01-29 at 10:24, Lunitix wrote:

> 
> I believe I am the more confused here.  But that being said, thanks for 
> showning me that it was a lack value being sent to the $_POST[sub_score] 
> that was creating the error on this page.  I used this to remedy the 
> situation -

Good for you.  I feel obligated to look over the code, so I'm noting
that you're missing some closing brackets, and some may not be doing
what you expect.
> 
> if ($_POST["add_score"]) {          // there is no closing bracket for this
> 	//calculating scores
> 	//print_r($_POST);
> 	list($key,$val)=each($_POST["add_score"]);
> 	$val=$val+$_POST["curval"];
> 	$sqlstring = "$key=$val";
> ----->		if ($_POST["sub_score"]) {
> 			$scoreval=TRUE;
> 		} else {
> thru			$scoreval=FALSE;
> 		}
> 		if ($scoreval) {
> 		while (list($key,$val)=each($_POST["sub_score"])) {
> 				$val=$val-$_POST["curval"];
> 				$sqlstring .= ",  $key=$val";
> ----->		} //end if for null "sub_score" ** this closes the "while"
> 	}  // end while ** this would close the "if ($scoreval)"

// missing closing "}" for first "if" statement.

BTW, unless you need "$scoreval" somewhere else, you could put the while
statement inside the if ($scoreval) statement to save yourself some
code.  

I still think 

if (is_array($_POST["sub_score"])) {
}

would be a better "if" statement.  It more accurately describes what
you're looking for.  If it's an array, it will be true, if it isn't an
array, it will be false.

The "if" statement you're using would be true (unfortunately) if for
some odd reason $_POST["sub_score"] becomes a string value, and then the
code will fail on the "each" statement.  Hey, stranger things have
happened.

> 
> And also, the help with the null $sql (changed to $sql="") in my 
> connecttodb.inc was very helpful.

great!

kind regards,

bill




More information about the Members mailing list