[PHP] If Statement Not Working

Status
Not open for further replies.

iRawrHotel

Member
Mar 4, 2012
41
0
Hello,
I'm coding a registration for my site, and trying to do an if statement, so that if in the database, register == 1, it shows the form, else it shows Registration Is Currently Disabled;
I currently have this;
$register = mysql_query("SELECT * FROM register")

PHP:
if ({$register} == 1)
{
echo "Form Here"
}
else {
echo "Registration Is Currently Disabled"
}

But i get
Code:
Parse error: syntax error, unexpected T_IF in /home/u872116037/public_html/register.html on line 55 Which is highlighted in the code above.

Any help would be appreciated!
 

Livar

Now 35% cooler!
Oct 15, 2010
846
86
Isn't it meant to be:

PHP:
if($register == "1")

+ is the value a text in the database, because if you converted it to text it'd still work.
 

Xenous

o shi
Nov 15, 2011
383
101
Hello,
I'm coding a registration for my site, and trying to do an if statement, so that if in the database, register == 1, it shows the form, else it shows Registration Is Currently Disabled;
I currently have this;
$register = mysql_query("SELECT * FROM register")

if ({$register} == 1)
{
echo "Form Here"
}
else {
echo "Registration Is Currently Disabled"
}

But i get
Parse error: syntax error, unexpected T_IF in /home/u872116037/public_html/register.html on line 55 Which is highlighted in the code above.

Any help would be appreciated!

Register is currently an object this why you can't use an if statement.
Also you're best off just using a config variable to determine whether one can register.
E.g
PHP:
// Array for Config variables
$Config['CanRegister'] = false; // False
 
if($Config['CanRegister'] == true)
{
    echo 'Forms and registration';
}
else
{
    echo 'Sorry registration is currently unavailable please check back later!';
}
 

iRawrHotel

Member
Mar 4, 2012
41
0
Register is currently an object this why you can't use an if statement.
Also you're best off just using a config variable to determine whether one can register.
E.g
PHP:
// Array for Config variables
$Config['CanRegister'] = false; // False
 
if($Config['CanRegister'] == true)
{
    echo 'Forms and registration';
}
else
{
    echo 'Sorry registration is currently unavailable please check back later!';
}




Thanks! I used your suggestion of a config variable and it works :)
 
Status
Not open for further replies.

Users who are viewing this thread

Top