Hi, having a slight problem which i cannot resolve. I am trying to retrieve a value from my database, database is as follows: websitesettings settingid settingname settingvalue 1 tocversion 1 2 regversion 1 3 publicenabled 0 there are 2 other files, admindblink.php and adminpanel.php Admin dblink.php includes the following... <?php session_start(); $Host = "localhost"; $user = "battles_gb75723n"; $Password = "********"; $DBName = "battles_battlesnails"; $link = mysql_connect ($Host, $user, $Password); if (isset($_SESSION['username'])){ if (isset($_SESSION['accesslevel'])){ // USERNAME IS LOGGED IN. NOW NEED TO CHECK THEIR ACCESS LEVEL (ENSURE THEY ARE NOT FROZEN) AND CHECK WEBSITE MAINTINENCE STATUS if ($_SESSION['accesslevel'] == "0"){ header ("Location: accountfrozen.php"); }elseif ($_SESSION['accesslevel'] == "2"){ }else{ header ("snailcastle.php"); } }else{ $_SESSION['username'] = ""; header ("Location: index.php"); } }else{ $_SESSION['accesslevel'] = ""; header ("Location: index.php"); } and the other file beginning is as follows... <?php require ("admindblink.php"); //******************************* //* find current website status * //******************************* $Query2 = "SELECT * FROM websitesettings WHERE 'settingid' = '3'"; $Result2 = mysql_db_query($DBName, $Query2, $link); while ($logininfo2 = mysql_fetch_array($Result2)){ $websitestatus = $logininfo2['settingvalue']; } if ($websitestatus == "0"){ $button = "enable site"; $status = "<font color='#ffffff'>Site disabled</font>"; $bgcolor = "red"; }else{ $button = "disable site"; $status = "<font color='#ffffff'>Site enabled</font>"; $bgcolor = "green"; } ?> <input type="submit" name="changestatus" value="<?php echo $button; ?>"> <?php echo $status; ?> - status = <?php echo $websitestatus; ?>. whiled = <?php echo $whiled; ?>. query statement = <?php echo $Query2; ?>, and result statement = <?php echo $Result2; ?></font> </form> Now the problem that i am getting is that the while statement is not activated (but no error messages occur). On page results are as follwos Site enabled - status = . whiled = . query statement = SELECT * FROM websitesettings WHERE 'settingid' = '3', and result statement = Resource id #4 If anyone can help me debug this and find the cause of the error i would appreciate it alot! ?>
Actually, according to the output you give, the WHILE is triggered, how else would you get "Site enabled" in your output? I skimmed your code a couple of times, it looks like it's doing what it's supposed to... what kind of output are you expecting? Also, since you're only fetching one value with $logininfo2, I recommend you use mysql_result instead of the while loop, then there's no need to loop and reassign variables and you'll get the actual value instead of "Resource id #4".
siteenabled = 0 which means website was disabled (so it shouldnt say it was enabled) - i found the error. read again: if ($websitestatus == "0"){ $button = "enable site"; $status = "<font color='#ffffff'>Site disabled</font>"; $bgcolor = "red"; }else{ $button = "disable site"; $status = "<font color='#ffffff'>Site enabled</font>"; $bgcolor = "green"; } It couldn't find the "websitestatus" variable, so displays status as site enabled. Figured it out in the end, if you are interested, this was the cause of the error.. $Query2 = "SELECT * FROM websitesettings WHERE 'settingid' = '3'"; There were 2 ' around "settingid" which should have not been there. That was invalidating the query, so it didn't want to work.