...

View Full Version : Check if certain condition is met



qutazs
06-28-2010, 08:26 PM
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.



<? 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:

<?
$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());
?>

Keleth
06-28-2010, 08:37 PM
So whats the question here?

qutazs
06-28-2010, 08:45 PM
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:

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:

<?
// 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.

Keleth
06-28-2010, 08:57 PM
So you need to know how to extract the data from the result?


$info = mysql_fetch_array($result);

$info becomes an array containing the returned columns.

qutazs
06-28-2010, 09:24 PM
Thanks alot!

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum