Page 1 of 1

Not going to the results page???

Posted: Wed Jan 17, 2007 10:15 pm
by cturner
Can someone please tell me why my code is displaying the following:
Please check the following and try again: and not going to the results page after someone has selected a radio button. This is driving me crazy. Thanks in advance. :?

Code: Select all

require "config.php"; 
		$shoesradiogroup = mysql_real_escape_string($_POST['shoesradiogroup']);
		$arrErrors = array();
		// the first submit button has been pressed
		if (isset($_POST['submitbtn1'])) {
			// no selection has been made with the first poll
			if (empty($shoesradiogroup)) {
				// so display an error
				$arrErrors['shoesradiogroup'] = 'Please select a poll option for the shoes poll.';
			} // end of empty($shoesradiogroup)
		if (count(arrErrors) == 0) {
			// if shopping cart has been selected
			if ($shoesradiogroup == 'shopcart') {
				// then select the shopping cart table
				$query = mysql_query("SELECT * FROM `shopcart`") or die ("Could not query because: " . mysql_error());
				// if nothing is in the shopping cart table
				if (mysql_affected_rows() == 0 ) {
					// then increment shopcart column
					$insert = "INSERT INTO `shopcart` (`shopcart`) VALUES (shopcart+1)";
				} else { // else use update to increment in the shopcart column
					if (mysql_query ($insert)) {						
						$update = "UPDATE `shoespoll` SET `shopcart` = shopcart+1";
							if (mysql_query($update)) {
								// no errors so set cookie
								setcookie('Voted', 'Voted');
								// cookie has been set
								if (isset ($_COOKIE[$cookie])) {
									// so go to the results page
									header ('Location: results.php');
								} // end of isset ($_COOKIE[$cookie])
							} else {
								print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
							} // end of mysql_query($update)
					} else {
						print "<p>Could not insert the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
					} // end of mysql_query($insert)
				} // end of mysql_affected_rows() == 0
			} // end of $shoesradiogroup == 'shopcart'
    	} else {
        	// The error array had something in it. There was an error.
        	// Start adding error text to an error string.
        	$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
        	// Get each error and add it to the error string
        	// as a list item.
        	foreach ($arrErrors as $error) {
            	$strError .= "<li>$error</li>";
      		} // end of foreach ($arrErrors as $error)
       		$strError .= '</ul></div>';
    	} // end of count(arrErrors) == 0
		} // end of isset($_POST['submitbtn1'])
mysql_close();

Posted: Wed Jan 17, 2007 11:34 pm
by volka
if (count(arrErrors) == 0)
missing a $ before arrErrors

You probably would have spotted this error earlier with error_reporting set to E_ALL and (display_errors=1 or watching the error log)
Notice: Use of undefined constant arrErrors - assumed 'arrErrors' in ....