Jump to content

The page isn't showing up


mfreitas

Recommended Posts

Sorry, could you please help me? I wrote this code but the page appears blank. It was ok but then I copied some functions and pasted below and i think i messed up the {} ;

I keep trying to count them, but when I change it still doesn't work....

Here it is:

 

<?php
$db = mysql_connect("localhost", "site", "password");
$basedados = "dbx" ;
mysql_select_db($basedados, $db) ;

$passi = $_COOKIE['codigo'] ;
$equipa = $_COOKIE['equipa'] ;
$idprop = $_COOKIE['idprop'] ;
$resposta = $_COOKIE['resposta'] ;


$resultj = mysql_query("SELECT Codigo FROM Codigo WHERE IDEquipa = '$equipa' ", $db) ;
while($row=mysql_fetch_array($resultj)) {
$test = $row['Codigo'] ;

}



$resultj = mysql_query("SELECT IDJogador FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
while($row=mysql_fetch_array($resultj)) {
$Jogador = $row['IDJogador'] ;

}








if($passi != $test) {
$Estado = "Transferência Cancelada: Password Incorrecta" ;

}
else {
        $resultjo = mysql_query("SELECT IDEquipa FROM Jogadores WHERE IDJogador = '$Jogador' ", $db) ;
        while($fu=mysql_fetch_array($resultjo)) {
        $eqjog = $fu['IDEquipa'] ;
}

if($eqjog == $equipa) {



$resultjo = mysql_query("SELECT Estado FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
        while($fu=mysql_fetch_array($resultjo)) {
        $estado = $fu['Estado'] ;
}


if($estado == 1) {
echo "Transferência Cancelada: A proposta já foi respondida..... " ;
}
else {



$qnum = mysql_query("SELECT Valor FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
while($tt = mysql_fetch_array($qnum)) {
$valor = $tt['Valor'] ;
}


$qnum = mysql_query("SELECT Tipo FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
while($tt = mysql_fetch_array($qnum)) {
$tipo = $tt['Tipo'] ;
}

	if($tipo == "PC") {

		if($resposta = "ACE") {

$resultj = mysql_query("SELECT IDEquipa FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
while($row=mysql_fetch_array($resultj)) {
$equipac = $row['Equipa'] ;
}


$qmovfin1 = mysql_query("INSERT INTO Mov_Fin VALUES ('VJ', '$equipa', '$valor', 'venda do jogador $Jogador') ", $db) ;
$qmovfin2 = mysql_query("INSERT INTO Mov_Fin VALUES ('CJ', '$equipac', '-$valor', 'compra do jogador $Jogador') ", $db) ;


$Saldoac = mysql_query("SELECT Saldo FROM Equipa WHERE IDEquipa = '$equipa' ", $db) ;
	while($ac = mysql_fetch_array($Saldoac)) {
	$saldo = $ac['Saldo'] ;
	}



$Saldoac = mysql_query("SELECT Saldo FROM Equipa WHERE IDEquipa = '$equipac' ", $db) ;
	while($ac = mysql_fetch_array($Saldoac)) {
	$saldo2 = $ac['Saldo'] ;
	}




$resultj = mysql_query("SELECT Preco FROM Val_Jog WHERE Valor = ( SELECT Valor FROM Jogadores WHERE IDJogador = '$Jogador') ", $db) ;
while($row=mysql_fetch_array($resultj)) {
$vjogador = $row['Valor'] ;
}



$Saldoac = mysql_query("SELECT ValPlantel FROM Equipa WHERE IDEquipa = '$equipa' ", $db) ;
	while($ac = mysql_fetch_array($Saldoac)) {
	$valp = $ac['ValPlantel'] ;
	}



$Saldoac = mysql_query("SELECT ValPlantel FROM Equipa WHERE IDEquipa = '$equipac' ", $db) ;
	while($ac = mysql_fetch_array($Saldoac)) {
	$valp2 = $ac['ValPlantel'] ;
	}

$nvalp = $valp - $vjogador ;

$nvalp2 = $valp2 + $vjogador ;

$qupdsaldo = mysql_query("UPDATE Equipa SET ValPlantel = '$nvalp' WHERE IDEquipa = '$equipa' ", $db) ;
$qupdsaldo = mysql_query("UPDATE Equipa SET ValPlantel = '$nvalp2' WHERE IDEquipa = '$equipac' ", $db) ;


$soma = $saldo + $valor ;

$qupdsaldo = mysql_query("UPDATE Equipa SET Saldo = '$soma' WHERE IDEquipa = '$equipa' ", $db) ;


$soma2 = $saldo2 - $valor ;

$qupdsaldo = mysql_query("UPDATE Equipa SET Saldo = '$soma2' WHERE IDEquipa = '$equipac' ", $db) ;



$qtransferencia = mysql_query("UPDATE Jogadores SET IDEquipa = '$equipac' WHERE IDJogador = '$Jogador' ", $db) ;



$updateprop = mysql_query("UPDATE Propostas SET Estado = 1 AND Descricao = 'Confirmada' WHERE IDProposta = '$idprop' ", $db) ; 



$resultjo = mysql_query("SELECT Nome FROM Jogadores WHERE IDJogador = '$Jogador' ", $db) ;
        while($fu=mysql_fetch_array($resultjo)) {
        $njogador = $fu['Nome'] ;
}



echo "O jogador $Jogador, $njogador, foi transferido. <br> Pertence agora ao $equipac , pelo valor de " ;
echo number_format($valor) ;
echo " ." ;

}
else {

$rej = mysql_query("UPDATE Propostas SET Estado = 1 AND Descricao = 'Rejeitada' WHERE IDProposta = '$idprop' ", $db) ;



echo "A Proposta do $equipac pelo jogador $Jogador , $njogador , foi rejeitada." ;






}

}
else {
	if($tipo == "PV") {

		if($resposta == "ACE") {

			$resultj = mysql_query("SELECT IDEquipa FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
			while($row=mysql_fetch_array($resultj)) {
			$equipac = $row['Equipa'] ;


			$qmovfin1 = mysql_query("INSERT INTO Mov_Fin VALUES ('VJ', '$equipac', '$valor', 'venda do jogador $Jogador') ", $db) ;
			$qmovfin2 = mysql_query("INSERT INTO Mov_Fin VALUES ('CJ', '$equipa', '-$valor', 'compra do jogador $Jogador') ", $db) ;


			$Saldoac = mysql_query("SELECT Saldo FROM Equipa WHERE IDEquipa = '$equipa' ", $db) ;
			while($ac = mysql_fetch_array($Saldoac)) {
			$saldo = $ac['Saldo'] ;
			}



			$Saldoac = mysql_query("SELECT Saldo FROM Equipa WHERE IDEquipa = '$equipac' ", $db) ;
			while($ac = mysql_fetch_array($Saldoac)) {
			$saldo2 = $ac['Saldo'] ;
			}




			$resultj = mysql_query("SELECT Preco FROM Val_Jog WHERE Valor = ( SELECT Valor FROM Jogadores WHERE IDJogador = '$Jogador') ", $db) ;
			while($row=mysql_fetch_array($resultj)) {
			$vjogador = $row['Valor'] ;
			}



			$Saldoac = mysql_query("SELECT ValPlantel FROM Equipa WHERE IDEquipa = '$equipa' ", $db) ;
			while($ac = mysql_fetch_array($Saldoac)) {
			$valp = $ac['ValPlantel'] ;
			}



			$Saldoac = mysql_query("SELECT ValPlantel FROM Equipa WHERE IDEquipa = '$equipac' ", $db) ;
				while($ac = mysql_fetch_array($Saldoac)) {
			$valp2 = $ac['ValPlantel'] ;
			}

			$nvalp = $valp + $vjogador ;

			$nvalp2 = $valp2 - $vjogador ;

			$qupdsaldo = mysql_query("UPDATE Equipa SET ValPlantel = '$nvalp' WHERE IDEquipa = '$equipa' ", $db) ;
			$qupdsaldo = mysql_query("UPDATE Equipa SET ValPlantel = '$nvalp2' WHERE IDEquipa = '$equipac' ", $db) ;


			$soma = $saldo - $valor ;

			$qupdsaldo = mysql_query("UPDATE Equipa SET Saldo = '$soma' WHERE IDEquipa = '$equipa' ", $db) ;


			$soma2 = $saldo2 + $valor ;

			$qupdsaldo = mysql_query("UPDATE Equipa SET Saldo = '$soma2' WHERE IDEquipa = '$equipac' ", $db) ;


			$qtransferencia = mysql_query("UPDATE Jogadores SET IDEquipa = '$equipa' WHERE IDJogador = '$Jogador' ", $db) ;



			$updateprop = mysql_query("UPDATE Propostas SET Estado = 1 AND Descricao = 'Confirmada' WHERE IDProposta = '$idprop' ", $db) ; 



			$resultjo = mysql_query("SELECT Nome FROM Jogadores WHERE IDJogador = '$Jogador' ", $db) ;
        			while($fu=mysql_fetch_array($resultjo)) {
        			$njogador = $fu['Nome'] ;
			}



			echo "O jogador $Jogador, $njogador, pertence agora ao seu clube. <br> O $equipa comprou-o assim por " ;
			echo number_format($valor) ;
			echo " ." ;	




		}
		else {




			echo " <br> O $equipa rejeitou a oferta do $equipac , de comprar <br> o jogador $Jogador , $njogador , de " ;
			echo number_format($valor) ;
			echo " ." ;


		}

	}
	else { 
			echo "CONTINUAR AQUI" ;
	}	



	}










}



}
   	else {
echo "ERRO: O jogador $Jogador não pertence ao $equipa " ;
        }


}
echo $Estado ;
echo "<br>" ;
echo $Final ;
?>

 

 

Thanks!

 

 

 

Link to comment
Share on other sites

I'm not sure what the problem is, but I'm not going to go through 300+ lines of code looking for it. But, I'll give you some advice on how to find it yourself.

 

1. Indent your code to match the logical code blocks. It looks like you attempted to do this, but it's not quite right. For example:

if($foo==$bar)
{
    //do something
    //Do something else
    if($x==$y)
    {
        //execute something
    }
    else
    {
         //Execute another thing here
    }
}

 

You have code blocks that put the conditional code on the same indent as the condition

   while($row=mysql_fetch_array($resultj)) {
   $vjogador = $row['Valor'] ;
   }

Also, why do you have all those while() loops that do nothing bug assign a value to a variable. If there should only be one record returned from the query then you don't need a while loop. If you expect many records then you are only left with the last value when the loop ends.

 

There is no reason for you to be running all those queries. Plus, you have no error handling on your query calls. So if there is a DB error you won't know it.

 

In any event that page is a complete mess - sorry to be blunt. I'm guessing you are new to programming and are trying to work it out as you write it. You need to take a step back and figure out the logic first (i suggest doing a rough draft on paper) then coding it.

 

For example, I see where you are apparently doing a query to get the password based upon a user name. You then assign the result from that query to the variable $test and check if that value matches the one in the cookie. But, that logic assumes that the user name is in the database. If it doesn't then $test will not even be defined.

 

Then the second query you have is before the test you have for the password. If that test does not pass you don't even use the results of that second query. So, that query would go after the test of the password. But, I see that all you do with the value from that query is use it is a subsequent query. So, instead of two queries, you should be using one.

 

Instead of (modified slightly)

$resultj = mysql_query("SELECT IDJogador FROM Propostas WHERE IDProposta = '$idprop' ", $db) ;
$row=mysql_fetch_array($resultj)
$Jogador = $row['IDJogador'];

$resultjo = mysql_query("SELECT IDEquipa FROM Jogadores WHERE IDJogador = '$Jogador' ", $db) ;
$fu=mysql_fetch_array($resultjo));
$eqjog = $fu['IDEquipa'] ;

 

You should use one query such as

$query = "SELECT Jogadores.IDEquipa
          FROM Jogadores
          JOIN Propostas USING (IDJogador)
          WHERE Propostas.IDProposta = '$idprop'";
$resultjo = mysql_query($query, $db) or die(mysql_erro());
if(!$resultjo)
{
    echo "Could not find IDEquipa";
}
else
{
    $fu=mysql_fetch_array($resultjo));
    $eqjog = $fu['IDEquipa'] ;
}

 

You are running lots of queries to get only one field of data, where you should instead be getting multiple pieces of data.

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.