Jump to content

Another error!!


adamjones

Recommended Posts

I wish I knew PHP, off by heart!

 

Ok. Earlier, a few guys helped to fix this code (cheers);

 

<?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 "<a href='turnmaintenanceoff.php'>Turn maintenance mode off</a>";
}
else
echo "<a href='turnmaintenanceon.php'>Turn maintenance mode on</a>";
}
?>

 

Now, when going to 'turnmaintenanceoff.php', It just echos my error. This is the 'turnmaintenanceoff.php' 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="UPDATE $tbl_name SET check='yes' WHERE check='no'";
$result=mysql_query($sql);

if($result){
echo "DONE";
else {
echo "ERROR";
}

?>

 

Sorry about asking for help, again!

Link to comment
https://forums.phpfreaks.com/topic/128003-another-error/
Share on other sites

Let's fix the first one properly:

 

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

while($rows=mysql_fetch_array($result)){
    if ($rows['check'] == yes) {
        echo "<a href='turnmaintenanceoff.php'>Turn maintenance mode off</a>";
    } else {
        echo "<a href='turnmaintenanceon.php'>Turn maintenance mode on</a>";
    }
}
?>

 

Note how proper indentation makes it obvious that you were a closing brace short in your code.

Link to comment
https://forums.phpfreaks.com/topic/128003-another-error/#findComment-662822
Share on other sites

Oh, Ok. I see. Thanks.

 

So now I have;

 

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

while($rows=mysql_fetch_array($result)){
    if ($rows['check'] == yes) {
        echo "<a href='turnmaintenanceoff.php'>Turn maintenance mode off</a>";
    } else {
        echo "<a href='turnmaintenanceon.php'>Turn maintenance mode on</a>";
    }
}
?>

 

and 'turnmaintenanceon.php' is;

 

<?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="UPDATE $tbl_name SET check='yes' WHERE check='no'";
$result=mysql_query($sql);

if($result){
echo "DONE";
}

else {
echo "ERROR";
}

?>

 

I just can't work out what's wrong.

Link to comment
https://forums.phpfreaks.com/topic/128003-another-error/#findComment-662826
Share on other sites

Try this. It sometime's solves problems for me.

 

<?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="UPDATE `$tbl_name` SET `check`='yes' WHERE `check`='no'";
$result=mysql_query($sql);

if($result){
echo "DONE";
}

else {
echo "ERROR";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/128003-another-error/#findComment-662829
Share on other sites

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.