Jump to content

Recommended Posts

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

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?

'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);

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

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");

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.

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.

@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 ===.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.