Page 1 of 1

why this script is not wroking?

Posted: Mon Apr 24, 2006 12:40 am
by Maluendaster
First of all, I'm a newby and i know i have like 30+ errors in this code.... I wanted to make a form where the user enter a numbers , and if the user enter the right number, it says he won, if he didn't enter the same number it says he lost, and if he enter nothing, display something like "You didn't entered any numbers"....

here's the code :

Code: Select all

<?php
$premio = 123456;
$codigo = $_POST['codigo'];
//////////////////////////////////////
if (isset($_POST['codigo'])) {
echo "No ingresaste ningun codigo";
}else{
if ($_POST['codigo'] == $premio) {
echo "GANASTE!! llama al siguiente telefono para confirmar tus datos!!";
}else{
echo "No ganaste, pero sigue intentando!"; }
?>
thank you

Posted: Mon Apr 24, 2006 1:46 am
by AshrakTheWhite

Code: Select all

<?php
$premio = '123456';
$codigo = $_POST['codigo'];
//////////////////////////////////////
if (empty($_POST['codigo'])) 
{
    echo "No ingresaste ningun codigo"; //nothing entered
}   else
    {
        if ($_POST['codigo'] == $premio) 
        {
            echo "GANASTE!! llama al siguiente telefono para confirmar tus datos!!"; // = 123456
        }   else
            {
                echo "No ganaste, pero sigue intentando!"; // != 123456
            }
    }
?>

solution

Posted: Mon Apr 24, 2006 1:50 am
by dibyendrah
Dear Ashrak,
You forgot to put the ending bracket of else.

Code: Select all

<?php
$premio = 123456;
$codigo = $_POST['codigo'];

if (isset($_POST['codigo'])) {
echo "No ingresaste ningun codigo";
}else{
if ($_POST['codigo'] == $premio) {
echo "GANASTE!! llama al siguiente telefono para confirmar tus datos!!";
}else{
echo "No ganaste, pero sigue intentando!"; 
}
}  <- You forgot to add this bracket
?>
Cheers,
Dibyendra

Posted: Mon Apr 24, 2006 2:05 am
by AshrakTheWhite
Doh sorry :p its 9am hehehehe

Posted: Mon Apr 24, 2006 11:05 am
by Maluendaster
thank you!