0

So after a long rest of coding(around 5months) i started to forgot some of the codes and i need help with this one, i cant find in the google with this topic, etc

enter image description here

code :

<?php

$num1 = "0";

$database = mysql_connect('x', 'x', 'x') or die ("Error x01");
mysql_select_db('x') or die ("Error x02");

$SQL1 = "Select * FROM 'server_status' WHERE on = '$num1'";
$result_id1 = @mysql_query($SQL1) or die("DATABASE ERROR!");
$total1 = mysql_num_rows($result_id1);

if($result1){
   echo "Server is under maintenance";
}

?>

right here i have a code where i'am gonna check the variable "on" in "server_status" table in my msql enter image description here

somehow even when i have my "on" variable on 0 (int not bool [join_protection is on int too]) it still gives out the die which is

or die ("DATABASE ERROR!");

i can't find how to fix that i played around with it and not managed to make it work

here's the result enter image description here

i'm looking forward for your answer thanks for passing by and helping me

regards, -itsproinc

5
  • 5
    can you please post text-based code and not an image of. This poses a problem and for a few reasons. Commented May 21, 2015 at 18:08
  • 2
    plus, this doesn't help you or die ("DATABASE ERROR!"); this does mysql_error() and remove the @ in @mysql_query it's an error suppressor. Commented May 21, 2015 at 18:10
  • yest thats the problem im trying to bypass the "or die" since it gives the correct value why would it show "or die" Commented May 21, 2015 at 18:12
  • I posted an answer for you below. Commented May 21, 2015 at 18:19
  • Actually, I spotted another issue, and I've made an additional edit to my answer in regards to your column name on. Do reload it if you've seen the first copy. Commented May 21, 2015 at 18:22

1 Answer 1

3

You're using single quotes which are not the correct Identifier Qualifiers around your table name, remove them.

FROM server_status

or use ticks: (which resemble quotes, but are not the same).

FROM `server_status`

Plus, you are using a MySQL reserved word, being on for your column name and it needs to be wrapped in ticks.

$SQL1 = "Select * FROM `server_status` WHERE `on` = '$num1'";

Plus, as I stated in comments:

This doesn't help you or die ("DATABASE ERROR!"); this does mysql_error() and remove the @ in @mysql_query it's an error suppressor.


Deprecation notice:

mysql_ is deprecated and will be removed from future PHP releases.

Use mysqli_ or PDO.

Better yet:

Use mysqli with prepared statements, or PDO with prepared statements, they're much safer.

Sign up to request clarification or add additional context in comments.

1 Comment

Thankyou, ill start using and learning mysqli_, thanks man i appreciate it :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.