[thelist] Null entry in form

Santilal Parbhu santilal at scorpioneng.co.nz
Wed Apr 25 05:24:02 CDT 2007


Hi

I am developing an appliciation in PHP4.  I use a form to collect results
from sports matches.  If the match has been played and the results have been
entered, those results are stored in a MySQL database.  The default value is
NULL.  Later I query the database and will use the data to update a points
table.  If the games haven't been played, the match is ignored.

I read a form and the way I determine if the the results have been entered
is to look to see if the form has a value in it.  If the value is NULL, then
the results are not entered.  (I was using 0-0 as a means of detecting that
the game has not been played, but then I realised that 0-0 can be a valid
result.)

My problem is that when I run the script to update the results into the
database, the database record changes from Null to a value of 0.  This
should occur for non-null entries but not for Null entries.  I need a null
entry to remain Null.  Can anyone see where my code is in error?  I think
that the UPDATE is not being skipped and the NULL is being updated to 0.

I have tried using Print statements as breakpoints in the code, but they
didn't print.  This tens to suggest that the code is not running, but it
must be, because the database is being updated.  Hope someone can help.

Thanks.

Santilal

foreach($HTTP_POST_VARS['match_id'] as $id){
		$score1=$HTTP_POST_VARS['score1'][$id]; 	//Read in the value of Score 1
from the form.
		$score2=$HTTP_POST_VARS['score2'][$id];   //Read in the value of Score 2
from the form.

		if ((isset($score1)) or (isset($score2))) {	 //If either Score1 or Score2
is not NULL, run the update.

	$query = "UPDATE $compdraw SET score1=('$score1'), score2=('$score2')
					WHERE row_id = '$id'  AND grade='$grd'";

		if($r = mysql_query ($query)){ // Execute the query.
		}else{ // Query didn't run.
					print '<div id="draw">';
					die ('<p>Could not retrieve the data because: <b>' . mysql_error() .
"</b>. The query was $query.</p>");
	}
	}
	}





More information about the thelist mailing list