[PHP] If the above statements is true, show this statement.

Results 1 to 7 of 7
  1. #1
    Sorcerer Supreme Illusion is offline
    Member +Rank
    Mar 2008 Join Date
    C:\Program Files\Adobe\Photoshop\Location
    457Posts

    [PHP] If the above statements is true, show this statement.

    I'm working on a little script (habbo online loader creator) and i'm pretty mutch done except for one thing.

    This is my page view.php
    PHP Code:
    $hname $_GET['hotelname'];
    $ip $_GET['ip'];
    $port $_GET['port'];
    $texts $_GET['texts'];
    $vars $_GET['vars'];
    $dcr $_GET['dcr'];
    $loader $_GET['loader'];
    $back "index.php";
    // HERE THE HNAME CONTROLS STARTS!

    if (
     !
    $hname || empty($hname)
    )
    {
       echo 
    "<font class=text>The <font class=error>hotel name</font> is empty!<br>";
    }
    // HERE THE HNAME CONTROLS END

    // HERE THE IP CONTROLS STARTS!

    if (
     !
    $ip || empty($ip)
    )
    {
       echo 
    "<font class=text>The <font class=error>IP</font> is empty!<br>";
    }
    // HERE THE IP CONTROLS ENDS!
    // HERE THE PORT CONTROLS STARTS!

     
    if (
     !
    $port || empty($port)
    )
    {
       echo 
    "<font class=text>The <font class=error>port</font> is empty!<br>
       "
    ;
    }
    // HERE THE PORT CONTROLS ENDS!
    // HERE THE TEXTS CONTROLS STARTS!

    if (
     !
    $texts || empty($texts)
    )
    {
       echo 
    "<font class=text>The <font class=error>texts</font> url is empty!<br>";
    }
    // HERE THE TEXTS CONTROLS END
    // HERE THE VARS CONTROLS STARTS!

    if (
     !
    $vars || empty($vars)
    )
    {
       echo 
    "<font class=text>The <font class=error>vars url</font> is empty!<br>";
    }
    // HERE THE VARS CONTROLS END
    // HERE THE DCR CONTROLS STARTS!

    if (
     !
    $dcr || empty($dcr)
    )
    {
       echo 
    "<font class=text>The <font class=error>DCR url</font> is empty!<br>";
    }
    // HERE THE DCR CONTROLS END


    else {
        
    // If none of the above statements is correct.

    echo "<font class=text>And your loader is done, all you have to do i copy and paste!<br><br>";
    echo 
    "<font class=text2>Code:</font>";

    echo 
    "<table class=code width=650 valign=top>
    <td class=code td valign=top>
    <font class=text2>
    <br>&lt;html>
    <br>&lt;head>
    <br>&lt;title><font class=info>
    $hname</font>&lt;/title>
    <br>&lt;base target=_blank>
    <br>&lt;/head>
    <br>&lt;body bgcolor=#000000 topmargin=0 link=#FFFFFF vlink=#FFFFFF alink=#FFFFFF>
    <br>&lt;div align=center>
    <br>&lt;param name=src value=>
    <br>&lt;param name=swRemote value=swSaveEnabled=true swVolume=true swRestart=false swPausePlay=false swFastForward=false swTitle=<font class=info>
    $hname</font> swContextMenu=true>
    <br>&lt;param name=swStretchStyle value=none>
    <br>&lt;param name=swText value=>
    <br>&lt;param name=bgColor value=#000000>
    <br>&lt;param name=sw6 value=external.texts.txt=<font class=info>
    $texts</font>>
    <br>&lt;param name=sw2 value=connection.info.host=<font class=info>
    $ip</font>;connection.info.port=<font class=info>$port</font>>
    <br>&lt;param name=sw4 value=connection.mus.host=;connection.mus.port=30 001>
    <br>&lt;param name=sw3 value=client.reload.url=<font class=info>
    $loader</font>>
    <br>&lt;param name=sw1 value=site.url=<font class=info>
    $loader</font>;url.prefix=<font class=info>$hname</font>>
    <br>&lt;param name=sw5 value=external.variables.txt=<font class=info>
    $vars</font>>
    <br>&lt;embed src=<font class=info>
    $dcr</font> bgColor=#000000 width=720 height=540 align=middle swRemote=swSaveEnabled=true swVolume=true swRestart=false swPausePlay=false swFastForward=false swTitle=massivewake swContextMenu=true swStretchStyle=none swText= type=application/x-director pluginspage=http://www.macromedia.com/shockwave/download/
    <br>sw6=external.texts.txt=<font class=info>
    $texts</font>
    <br>sw2=connection.info.host=<font class=info>
    $ip</font>;connection.info.port=<font class=info>$port</font>
    <br>sw4=connection.mus.host=;connection.mus.port=30001
    <br>sw3=client.reload.url=<font class=info>
    $dcr</font>
    <br>sw1=site.url=<font class=info>
    $loader</font>;url.prefix=<font class=info>$hname</font>
    <br>sw5=external.variables.txt=<font class=info>
    $vars</font>>
    <br>&lt;/div>
    <br>&lt;/body>
    <br>&lt;/html>

    </td>
    </table>"
    ;
    echo 
    "<br><font class=text>(All your info is marked <font class=info>red</font>!)</font>.";
    echo 
    "<br><br><a href=index.php><font class=text>Make a new loader (back to index)</a>.";
    }



    ?> 
    And i wan't to add another if before the else, but i wan't it to show only if one of the above statements are true, (the if will containt a back button).
    But i have no idea how to do that. Any help from you guys?


  2. #2
    Grand Master john_d is offline
    Grand MasterRank
    Feb 2004 Join Date
    PhilippinesLocation
    2,868Posts

    Re: [PHP] If the above statements is true, show this statement.

    too many IF'sssss

    try to load ur variables in an array like

    $config['hname'] = ;

    then jsut run thru all of them with foreach

  3. #3
    Sorcerer Supreme Illusion is offline
    Member +Rank
    Mar 2008 Join Date
    C:\Program Files\Adobe\Photoshop\Location
    457Posts

    Re: [PHP] If the above statements is true, show this statement.

    You'll have to explain more, since i am a beginner in php.

    Can anybody just explain?
    Last edited by Illusion; 12-08-08 at 11:28 PM.

  4. #4
    Member Airon is offline
    MemberRank
    Feb 2008 Join Date
    32Posts

    Re: [PHP] If the above statements is true, show this statement.

    I had a similar problem I guess you could say. Daevius helped me with this. What you do is set a boolean. You define it earlier in your script. $valid = true;

    PHP Code:
    <?
    /* Define the Boolean here */
    $valid false
    /* Just Putting this so you notice it */
    $hname $_GET['hotelname'];
    $ip $_GET['ip'];
    $port $_GET['port'];
    $texts $_GET['texts'];
    $vars $_GET['vars'];
    $dcr $_GET['dcr'];
    $loader $_GET['loader'];
    $back "index.php";
    // HERE THE HNAME CONTROLS STARTS!

    if (!$hname || empty($hname))
    {
       echo 
    "<font class=text>The <font class=error>hotel name</font> is empty!<br>";
       
    $valid false;
    }
    // HERE THE HNAME CONTROLS END

    // HERE THE IP CONTROLS STARTS!

    if (!$ip || empty($ip))
    {
       echo 
    "<font class=text>The <font class=error>IP</font> is empty!<br>";
       
    $valid false
    }
    // HERE THE IP CONTROLS ENDS!
    // HERE THE PORT CONTROLS STARTS!

     
    if (!$port || empty($port))
    {
       echo 
    "<font class=text>The <font class=error>port</font> is empty!<br>";
       
    $valid flase;
    }
    // HERE THE PORT CONTROLS ENDS!
    // HERE THE TEXTS CONTROLS STARTS!

    if (
     !
    $texts || empty($texts)
    )
    {
       echo 
    "<font class=text>The <font class=error>texts</font> url is empty!<br>";
       
    $valid false;
    }
    // HERE THE TEXTS CONTROLS END
    // HERE THE VARS CONTROLS STARTS!

    if (
     !
    $vars || empty($vars)
    )
    {
       echo 
    "<font class=text>The <font class=error>vars url</font> is empty!<br>";
       
    $valid false;
    }
    // HERE THE VARS CONTROLS END
    // HERE THE DCR CONTROLS STARTS!

    if (
     !
    $dcr || empty($dcr)
    )
    {
       echo 
    "<font class=text>The <font class=error>DCR url</font> is empty!<br>";
       
    $valid false;
    }
    // HERE THE DCR CONTROLS END


    if($valid)
    {
        
    // If none of the above statements is correct.

    echo "<font class=text>And your loader is done, all you have to do i copy and paste!<br><br>";
    echo 
    "<font class=text2>Code:</font>";

    echo 
    "<table class=code width=650 valign=top>
    <td class=code td valign=top>
    <font class=text2>
    <br>&lt;html>
    <br>&lt;head>
    <br>&lt;title><font class=info>
    $hname</font>&lt;/title>
    <br>&lt;base target=_blank>
    <br>&lt;/head>
    <br>&lt;body bgcolor=#000000 topmargin=0 link=#FFFFFF vlink=#FFFFFF alink=#FFFFFF>
    <br>&lt;div align=center>
    <br>&lt;param name=src value=>
    <br>&lt;param name=swRemote value=swSaveEnabled=true swVolume=true swRestart=false swPausePlay=false swFastForward=false swTitle=<font class=info>
    $hname</font> swContextMenu=true>
    <br>&lt;param name=swStretchStyle value=none>
    <br>&lt;param name=swText value=>
    <br>&lt;param name=bgColor value=#000000>
    <br>&lt;param name=sw6 value=external.texts.txt=<font class=info>
    $texts</font>>
    <br>&lt;param name=sw2 value=connection.info.host=<font class=info>
    $ip</font>;connection.info.port=<font class=info>$port</font>>
    <br>&lt;param name=sw4 value=connection.mus.host=;connection.mus.port=30 001>
    <br>&lt;param name=sw3 value=client.reload.url=<font class=info>
    $loader</font>>
    <br>&lt;param name=sw1 value=site.url=<font class=info>
    $loader</font>;url.prefix=<font class=info>$hname</font>>
    <br>&lt;param name=sw5 value=external.variables.txt=<font class=info>
    $vars</font>>
    <br>&lt;embed src=<font class=info>
    $dcr</font> bgColor=#000000 width=720 height=540 align=middle swRemote=swSaveEnabled=true swVolume=true swRestart=false swPausePlay=false swFastForward=false swTitle=massivewake swContextMenu=true swStretchStyle=none swText= type=application/x-director pluginspage=http://www.macromedia.com/shockwave/download/
    <br>sw6=external.texts.txt=<font class=info>
    $texts</font>
    <br>sw2=connection.info.host=<font class=info>
    $ip</font>;connection.info.port=<font class=info>$port</font>
    <br>sw4=connection.mus.host=;connection.mus.port=30001
    <br>sw3=client.reload.url=<font class=info>
    $dcr</font>
    <br>sw1=site.url=<font class=info>
    $loader</font>;url.prefix=<font class=info>$hname</font>
    <br>sw5=external.variables.txt=<font class=info>
    $vars</font>>
    <br>&lt;/div>
    <br>&lt;/body>
    <br>&lt;/html>

    </td>
    </table>"
    ;
    echo 
    "<br><font class=text>(All your info is marked <font class=info>red</font>!)</font>.";
    echo 
    "<br><br><a href=index.php><font class=text>Make a new loader (back to index)</a>.";
    }
    ?>
    Hopefully this works x_x Good luck.

  5. #5
    Grand Master john_d is offline
    Grand MasterRank
    Feb 2004 Join Date
    PhilippinesLocation
    2,868Posts

    Re: [PHP] If the above statements is true, show this statement.

    PHP Code:
    $check['hname'] = $_GET['hotelname'];
    $check['ip'] = $_GET['ip'];
    $check['port'] = $_GET['port'];
    $check['texts'] = $_GET['texts'];
    $check['vars'] = $_GET['vars'];
    $check['dcr'] = $_GET['dcr'];
    $check['loader'] = $_GET['loader'];
    $check false;

    foreach (
    $check as $key => $k) {
        if (!
    $k || empty($k)  {
    echo 
    "<font class=text>The <font class=error>".$key."</font> is empty!<br>";
       
    $check false;
       } else {
    // do ur stuff here
       
    }
    }

    if (
    $valid == false) {
     
    //form here

    basically does the same thing.. u can even make it shorter by just looping thru the GET variables

  6. #6
    The Gamma..? EliteGM is offline
    Grand MasterRank
    Jul 2006 Join Date
    NandolandLocation
    4,077Posts

    Re: [PHP] If the above statements is true, show this statement.

    I usually do something like;
    PHP Code:
    <?php
    if ($_GET['blabla'] == '')
    {
    $msg "Blabla is empty!";
    $c 1;
    }
    //more if's

    if ($c != 1)
    {
    //form
    }

    //in the html, just put <?=$msg;? > (without the space) where you want the message to display.
    ?>

  7. #7
    Member fook3d is offline
    MemberRank
    Sep 2007 Join Date
    Leicester, UKLocation
    65Posts

    Re: [PHP] If the above statements is true, show this statement.

    There is no reason to even convert the $_GET into $variable['whatever'], You can simply do:

    PHP Code:
    <?php
    $error 
    FALSE;
    foreach (
    $_GET as $key => $var)
    {
        if(!
    strlen($var) OR eregi('[^a-z0-9]'$var))
        {
            echo 
    '<font class="text">The <font class="error">' $key '</font> field is empty or contains non alphanumeric characters!';
            echo 
    '<br />';
            
    $error TRUE;
        }
    }

    if(
    $error == TRUE)
    {
        echo 
    'Errors encountered are listed above.';
    }
    ?>
    Last edited by fook3d; 13-08-08 at 12:11 PM. Reason: Updated script to add an eregi to check alphanumeric input.



Advertisement