Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/03/2009, 11:55
lauchalp95
 
Fecha de Ingreso: julio-2006
Mensajes: 254
Antigüedad: 17 años, 10 meses
Puntos: 0
Problema con juego php

Tengo un juego en donde se da un numero al azar y debe ser encontrado por la pagina juegos/boletos/index.php cuando es encontrado se envia via formulario. En index.php se crea si no existe una session llamada jugada_b y en index2.php se procesa si el numero seleccionado es igual al dado al azar, y si es asi, se ejecutan unas acciones.
Aqui pongo el codigo y mas abajo el error:
INDEX.php
Código PHP:

<?php

//CONEXION
 
?>
        
<?php


if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_Noone$Noone);
$query_bote "SELECT * FROM pozo WHERE pozo = 'boletos'";
$bote mysql_query($query_bote$Noone) or die(mysql_error());
$row_bote mysql_fetch_assoc($bote);
$totalRows_bote mysql_num_rows($bote);mysql_select_db($database_Noone$Noone);
$query_bote "SELECT * FROM pozo WHERE pozo = 'boletos'";
$bote mysql_query($query_bote$Noone) or die(mysql_error());
$row_bote mysql_fetch_assoc($bote);
$totalRows_bote mysql_num_rows($bote);

$colname_banco "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_banco $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_banco sprintf("SELECT * FROM banco WHERE usuario = %s"GetSQLValueString($colname_banco"text"));
$banco mysql_query($query_banco$Noone) or die(mysql_error());
$row_banco mysql_fetch_assoc($banco);
$totalRows_banco mysql_num_rows($banco);
 
?>
        
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

</head>

<body>
<div align="left" class="Estilo1 Estilo3">Encuentra el boleto!</div>
<p align="center" class="Estilo2"><em>A Nooni se le cayó el boleto de su tren! El esta buscando por toda la estacion, pero hay muchos boletos! ¿Lo ayudas a encontrar el suyo?</em></p>
<p align="center" class="Estilo2">¿Podrás encontrar el boleto que le corresponde a Nooni? Su boleto era el numero <b><u><? $azar rand(1,10); echo"$azar";  ?></u></b></p>
<p align="center" class="Estilo2"><strong><span class="important">Debes encontrar el </span><span class="important"> boleto con la identificacion </span></strong><b><u><b><u>
  <? echo "$azar" ;  ?></u></b></u></b><br />
<span class="cxhiqi"><span class="cxhiqi">(sean</span> los que sean)</span></p>
<p align="center" class="Estilo2"><em><strong>A veces, puede que no puedas ayudar a Nooni y no pueda tomarse el tren.</strong></em><br />
¡Agarraste 100 boletos del suelo! ¿Podrás encontrar a el  correcto?<br />
<a href="/juegos/boleto/index.php">ACTUALIZAR </a><br />
</p>
<p align="center" class="Estilo2"><? if($row_banco['nooney'] < 150)
{
    echo 
"No tienes suficientes nooney";
}
else
{
    
        
/* Se descuentan 150 Nooney */
$user $_SESSION['MM_Username'];
    
$precio 150;
    
$restar $row_banco['nooney'] - $precio;
    
$hacer mysql_query("UPDATE banco SET nooney = $restar WHERE usuario = '$user'") or die(mysql_error());
    echo 
"¡Se te descontaron 150 Nooney!" ;

    
/* Agregar al pozo */
$pozo $row_bote['nooney'];
$sumar $pozo $precio;
$sumari mysql_query("UPDATE pozo SET nooney = $sumar WHERE pozo = 'boletos'") or die(mysql_error());
echo 
" ¡Y se agregaron al pozo! ";
if(isset(
$_SESSION['jugada_b']))
{
    echo 
" ¡Juega! ";
    echo 
" $_SESSION[jugada_b] ";
}
else
{
    
$_SESSION['jugada_b'] = 0;
}



}
 
?><br />
  <br />
<em><strong>Bote actual:</strong></em><strong></strong> <?php echo $row_bote['nooney']; ?> Nooney<br />
<br />
Selecciona 4 veces seguidas el boleto correcto y ganaras el pozo<br />
</p><?
//FORMULARIO PARA ELEGIR EL MISMO NUMERO QUE EL DADO AL AZAR
?>
INDEX2.PHP
Código PHP:


<?php
//CONEXION
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$colname_datos "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_datos $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_datos sprintf("SELECT juego, usuario, data1 FROM juegos WHERE usuario = %s"GetSQLValueString($colname_datos"text"));
$datos mysql_query($query_datos$Noone) or die(mysql_error());
$row_datos mysql_fetch_assoc($datos);
$totalRows_datos mysql_num_rows($datos);

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_Recordset1 $_SESSION['MM_Username'];
}
mysql_select_db($database_Noone$Noone);
$query_Recordset1 sprintf("SELECT * FROM banco WHERE usuario = %s"GetSQLValueString($colname_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$Noone) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_Noone$Noone);
$query_Recordset2 "SELECT * FROM pozo WHERE pozo = 'boletos'";
$Recordset2 mysql_query($query_Recordset2$Noone) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);


$id $_POST['azar']; 
 
$elegido $_POST['elegido'];  ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>

</head>

<body>
<div align="left" class="Estilo1 Estilo3">Jugando a ¡Encuentra el boleto!</div>
<p align="center" class="Estilo2"><em>El numero de boleto era <? echo " $id " ?> </em></p>
<p align="center" class="Estilo2"><span class="contenido">Tu has marcado el boleto numero: </span><br />
<? echo " $elegido $_SESSION[jugada_b] "?>
</p>
<p align="center" class="Estilo2"><?
//VERIFICO SE CONCUERDAN
if($id == $elegido)
//SI CONCUERDAN PASA ESTO
{
    echo 
" Los numeros concuerdan, has ganado ";
//SI SESSION ESTA EN 0
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 0)
                       {
                           echo 
" Esta es tu primer jugada acertada ";
                           
$_SESSION[jugada_b] = 1;
                       }
                   }
//SI ESTA EN 1
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 1)
                       {
                           echo 
" Esta es tu segunda jugada acertada ";
                           
$_SESSION[jugada_b] = 2;
                       }
                   }
//SI ESTA EN 2
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 2)
                       {
                           echo 
" Esta es tu tercera jugada acertada ";
                           
$_SESSION[jugada_b] = 3;
                       }
                   }
//SI ESTA EN 3
if(isset($_SESSION[jugada_b]))
                   {
                       if(
$_SESSION[jugada_b] == 3)
                       {
                           echo 
" HAS GANADO EL BOTE!!!!!!!!!!!!!! ";
                           
                           
//DAR BOTE
                           
$bote $row_Recordset2['nooney'];
                           
$atual $row_Recordset1['nooney'];
                           
$suma $atual $bote;
                           
$upd mysql_query("UPDATE banco SET nooney = $suma WHERE usuario = $_SESSION[MM_Username] ");
                           
$_SESSION[jugada_b] = 0;
                       }
                   }
                   
                   
//SI NO EXISTE SSION
                   
if(isset($_SESSION[jugada_b]))
                   {
                      echo 
"Gracias por jugar" ;
                      }
                      else
                      {
                          echo 
" Ocurrio un error ";
                      }
//SINO ESTO
}
else
{
    echo 
" Los numeros que has elegido no concuerdan... ";
}

echo 
" $_SESSION[jugada_b]";



















?>
<p align="center" class="Estilo2">&nbsp; </p>
<p align="center" class="Estilo2"><a href="/juegos/boleto/index.php">Volver a jugar</a></p>
</body>
</html>
<?php
mysql_free_result
($datos);

mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>
El error sucede en index2.php
cuando me imprime esto:
Cita:
Los numeros concuerdan, has ganado Esta es tu primer jugada acertada Esta es tu segunda jugada acertada Esta es tu tercera jugada acertada HAS GANADO EL BOTE!!!!!!!!!!!!!! Gracias por jugar 0
Osea, me imprime TODO , y luego la variable vuelve a 0.
¿Alguien sabe porque me sucede esto?