Jump to content

[SOLVED] Can someone please fix my code?


adamjones

Recommended Posts

Ok. I have wrote this code;

 

<?php
$host="localhost";
$username="wowdream_domaine";
$password="PASS";
$db_name="wowdream_domaine";
$tbl_name="maintenance";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<?php
while($rows=mysql_fetch_array($result)){
?>
<? if ($rows['check'] = yes) {
echo "Turn maintenance mode off";
}
else
echo "Turn maintenance mode on";
}
?>

The problem is, it always echo's "Turn maintenance mode off", even if the value in my table is set to something else. I'm guessing I have an error in my code, right?

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/127998-solved-can-someone-please-fix-my-code/
Share on other sites

EDIT: Beaten to it

This line is the issue:

if ($rows['check'] = yes) {

Use the comparion operator (==) not the assignment operator (=)

 

Also I advise you to avoid using short tags (<? ?> or <?= ?>). Using short tags makes your code less portable as not all PHP installations have short tags enabled.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.