Strange redirect problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
packito
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 1:53 pm

Strange redirect problem!

Post by packito »

Hi everybody!

I want to redirect users from a page to one of two pages, according to the following condition:
-when a user votes on a certain item, if his/her vote already exists in the certain table from my database (table reg_votos) he is supposed to not be able to vote and go to page "VotosNotOK";
-on the other hand, if there isn't any entrance in the table of the user's IP together with the vote he/her intends to make, the user must go to "VotosOK"

For that i'm using the following code:

Code: Select all

<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
?>
<?php
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
$id_autor=$_GET['id_autor'];
$userIP=$_SERVER['REMOTE_ADDR'];
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form_rimas")) {
	$procuraSQL = "SELECT COUNT(*) FROM reg_votos WHERE endIP='$userIP' AND rima='$id_autor'";
	mysql_select_db($database_connRapMania, $connRapMania);
	$procura = mysql_query($procuraSQL, $connRapMania) or die(mysql_error());
	while ($row_resultadosProcura = mysql_fetch_assoc($procura)) {
	$existe=(int)$row_resultadosProcura['COUNT(*)'];
	if ($existe == 0){// vote do not exists
	 	$updateSQL = sprintf("UPDATE rimas_00 SET pontos=pontos+%s WHERE id=%s",
						GetSQLValueString($HTTP_POST_VARS['votos'], "int"),
						GetSQLValueString($HTTP_POST_VARS['hiddenID'], "int"));
		mysql_select_db($database_connRapMania, $connRapMania);
		$Result1 = mysql_query($updateSQL, $connRapMania) or die(mysql_error());
		//insert vote in database
		$updateVotos = "INSERT INTO reg_votos (endIP, rima) VALUES ('$userIP', '$id_autor')";
		mysql_select_db($database_connRapMania, $connRapMania);
		$ResultVotos = mysql_query($updateVotos, $connRapMania) or die(mysql_error());
		$updateGoTo = "votosOK.php";
		if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    		$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
		    $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
		}
		//header(sprintf("Location: %s", $updateGoTo));
	}
	else{
  		$updateGoTo = "votosNotOK.php";
  		if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
		    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    		$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  		}
	  	//header(sprintf("Location: %s", $updateGoTo));
	}
	}// end while
	mysql_free_result($procura);
	header(sprintf("Location: %s", $updateGoTo));
}//end if issset $HTTP

[... remaining and necessary code to display the voting page goes here..]
?>
Now i'm dealing with this situation:

when the user can vote (i.e., it is the first time that user votes on that item) the page is correctly redirected to "VotosOK". However, when that is not the case, thus the voting page should be redirected to "VotosNotOk" page, i get this error message:

"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:"

According to this topic of the forum - viewtopic.php?t=1157, this type of error is due to trying to send content to the browser before sending header information. Can someone explain me which content is being sent when user is supposed to go to "VotosNotOK"? And also, why it does not happen when one is redirected to the "VotosOk" page?!?

Is there any other reason why this is happening?

HELP please! 8O
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

That error tends to be IIS's 'page not found error' for PHP. Are you trying to access a virtual directory? Have you made sure that the file exists where you are trying to access it from?

Mac
packito
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 1:53 pm

Post by packito »

yes, the file exists where i'm trying to access it.

Still don't know where the problem is :cry:
packito
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 1:53 pm

problem solved!

Post by packito »

yeap, there is a file where i'm trying to access it.. but with some other name!
Oopps, silly me! :oops:

Thanks for the tip, twigletmac.
Problem solved!
Post Reply