Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if certain condition is met

    Hello,

    i'm trying to make a php script, which will check to see if a certain "code" is matching a code in my MySQL database.

    Im trying to make a killswitch, and this is part of it.

    PHP Code:
    <? include('connect.php'); ?>
    <?
    if ($ks == '12qwaszx!"QWASZX')
        print(
    "Website is live - Killswitch is OFF");
    else
        print(
    "Killswitch is ON!");
    ?>
    the $ks should get the value from the MySQL db, and then check if the one written beside it is the same.

    If it is! It should show "Website is live - Killswitch if OFF".
    Otherwise it should show: "Killswitch is ON!"

    The content of my connect.php is:
    PHP Code:
    <?
    $host 
    'HIDDEN';
    $user 'HIDDEN';
    $pass 'HIDDEN';
    $db 'HIDDEN';


    // The database connect part
    mysql_connect("$host""$user""$pass") or die(mysql_error());
    mysql_select_db("$db") or die(mysql_error());

    // Fetch Stuff
    $q "SELECT * FROM killswitch";
    $result mysql_query($q) or die(mysql_error());
    ?>
    Last edited by qutazs; 06-28-2010 at 08:37 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    So whats the question here?

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The question is, how do I make it check the $ks value in the database?
    The value "12qwaszx!"QWASZX" is in my database, so the part:
    PHP Code:
    if ($ks == '12qwaszx!"QWASZX'
    Should, well.. be TRUE and show the website.

    If I then change my database record to 12qwaszx!"QWASZX1111
    It should be FALSE, and therfor show that the killswitch is ON and thus, disabling the website.



    The following works:
    PHP Code:
    <?
    // Setting $ks to 0 turns killswitch ON, 1 makes the website go live.
    $ks 1;

    if (
    $ks == 1)
        print(
    "Website is live - Killswitch is OFF");
    else
        print(
    "Killswitch is ON!");
    ?>
    But I need to be able to change the value in my database, and not in the script itself.
    Last edited by qutazs; 06-28-2010 at 08:49 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    So you need to know how to extract the data from the result?

    PHP Code:
    $info mysql_fetch_array($result); 
    $info becomes an array containing the returned columns.

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks alot!

    I had already tried using arrays, but not in this way. Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •