Lamez Posted July 1, 2008 Share Posted July 1, 2008 I been looking over and over this block of code for a while now, I think I need a fresh pair of eyes here is the code: <?php ob_start(); $path = ""; $title = "Register"; $login = "no"; $ban = "no"; include ($path."main/include/cons/head.php"); echo '<p class="header">Register</p>'; //Check to see if reg. is enabled //1=>disabled, 0=>enabled $r = mysql_query("SELECT * FROM `pgs`"); $row = mysql_fetch_array($r); if ($row['reg'] == ('1')){ echo '<p class="maintext">Registation is disabled at the moment.</p>'; include ($path."main/include/cons/foot.php"); exit; } else { //check to see if passgate is on //1=>on 0=>off $q = mysql_query("SELECT * FROM `site_status`"); $db = mysql_fetch_array($q); if($db['pass_on_reg'] == ('1')){ if (!isset($_SESSION['pass'])){ echo "pass gate"; exit; } }else{ echo "page page page page"; } } include ($path."main/include/cons/foot.php"); what is happening is I set a 1 in the database to enable the passgate, so the code should echo out "pass gate", but it does not, all it says is "page page..." am I doing somthing wrong? Thanks for the help..again. -Lamez Quote Link to comment Share on other sites More sharing options...
JD* Posted July 1, 2008 Share Posted July 1, 2008 Try instead: if ($row['reg'] == '1'){ Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 What kind of field is it? Is it an INT or a VARCHAR. If it's an integer, then you shouldn't use quotes. It makes it a string. And vice versa. Also you don't need the parentheses wrapped around the comparison. Quote Link to comment Share on other sites More sharing options...
Lamez Posted July 1, 2008 Author Share Posted July 1, 2008 now nothing is being echoed out here is what I changed: <?php ob_start(); $path = ""; $title = "Register"; $login = "no"; $ban = "no"; include ($path."main/include/cons/head.php"); echo '<p class="header">Register</p>'; $r = mysql_query("SELECT * FROM `pgs`"); $row = mysql_fetch_array($r); if ($row['reg'] == ('1'){ echo '<p class="maintext">Registation is disabled at the moment.</p>'; include ($path."main/include/cons/foot.php"); exit; } else { $q = mysql_query("SELECT * FROM `site_status`"); $db = mysql_fetch_array($q); if ($db['pass_on_reg'] == (1){ if (!isset($_SESSION['pass'])){ echo "pass gate"; exit; } }else{ echo "page page page page"; } } include ($path."main/include/cons/foot.php"); the disabled one is a varchar, the other is a int I get a blank page now, why? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted July 1, 2008 Share Posted July 1, 2008 '1' vs. 1 shouldn't be an issue. i'd check to make sure your mysql_query()'s aren't erring. you also might not be getting the associative array you expect with mysql_fetch_array(). $r = mysql_query("SELECT * FROM `pgs`") or die (mysql_error()); $row = mysql_fetch_assoc($r); // OR // $row = mysql_fetch_array($r, MYSQL_ASSOC); Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 You're not being very clear, but it's because you're still using parentheses. Here's an example of how it should be done. <?php $myVar1 = 1; // An integer $myVar2 = '1'; // A string if($myVar1 == 1) { echo 'My variable is an integer, Wahoo!'; } if($myVar2 == '1') { echo 'My variable is a string, Wahoo!'; } ?> Also stick error handling on. error_reporting(E_ALL); Also use mysql_error() for your queries. $query = mysql_query("query...") or trigger_error(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Lamez Posted July 1, 2008 Author Share Posted July 1, 2008 oh I understand now, I changed it, and all it is echoing out is "page page page..." here is my current code now: <?php ob_start(); $path = ""; $title = "Register"; $login = "no"; $ban = "no"; include ($path."main/include/cons/head.php"); echo '<p class="header">Register</p>'; //$r = mysql_query("SELECT * FROM `pgs`"); //$row = mysql_fetch_array($r); $r = mysql_query("SELECT * FROM `pgs`") or die (mysql_error()); $row = mysql_fetch_assoc($r); if ($row['reg'] == (1)){ echo '<p class="maintext">Registation is disabled at the moment.</p>'; include ($path."main/include/cons/foot.php"); exit; } else { /* $q = mysql_query("SELECT * FROM `site_status`"); $db = mysql_fetch_array($q);*/ $r = mysql_query("SELECT * FROM `site_status`") or die (mysql_error()); $row = mysql_fetch_assoc($r); if ($row['pass_on_reg'] == ('1')){ if (!isset($_SESSION['pass'])){ echo "pass gate"; exit; } }else{ echo "page page page page"; } } include ($path."main/include/cons/foot.php"); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 You're not being very clear, but it's because you're still using parentheses. Here's an example of how it should be done. <?php $myVar1 = 1; // An integer $myVar2 = 1; // A string if($myVar1 == 1) { echo 'My variable is an integer, Wahoo!'; } if($myVar2 == '1') { echo 'My variable is a string, Wahoo!'; } ?> They'll both display the message regardless of ' ' because PHP is a loosely typed language unlike C++ and stuff. Quote Link to comment Share on other sites More sharing options...
Lamez Posted July 1, 2008 Author Share Posted July 1, 2008 I got it fixed, the current code worked, lol I forgot to uplaod it Thanks guys Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 You're not being very clear, but it's because you're still using parentheses. Here's an example of how it should be done. <?php $myVar1 = 1; // An integer $myVar2 = 1; // A string if($myVar1 == 1) { echo 'My variable is an integer, Wahoo!'; } if($myVar2 == '1') { echo 'My variable is a string, Wahoo!'; } ?> They'll both display the message regardless of ' ' because PHP is a loosely typed language unlike C++ and stuff. Yes, PHP is a loosely typed language. However, declaring and comparing variables should, in my opinion be done the way it's supposed to be done. In my experience, it makes debugging much easier, and should reduce the chances of problems such as declaration issues, syntactical/parse errors from occurring. But again, that's just my opinion. I'm pretty strict when it comes to writing clean and easy to read code. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 @Wolphie: I'm not debating the fact that variables should be assigned as the types that you want them to be, but I'm saying that regardless of how you set it (in the case of '1'), it'll echo those messages. If it was truly "strict", then you'd use ===. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.