Problem with mysql

Username : epiz_31025917

Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘SELECT * FROM Section_Keys

I don’t think this problem with the query because it works when I use it in phpmyadmin but when I try this query from a php file hosted in my site it pops this error.

My code:
$query=‘SELECT * FROM Section_Keys;’ ;
$result=mysqli_query($conn,$query);

What happens if you omit the backticks (`) in the PHP SQL query?

YoYou have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘SELECT * FROM Section_Keys’ at line 1

Then It also changes the back ticks from error

Can you verify that you use:

  1. The correct connection
  2. The correct Table

Can you kindly share the connection statement? Remember to hide the password!

1 Like

$mysql_username=“epiz_31025917”; $mysql_server=“sql307.epizy.com”;

$mysql_password=“password”;

$mysqd_db=“epiz_31025917_Aime”;

$conn=mysqli_connect($mysql_server,$mysql_username,$mysql_password,$mysqd_db);

And I checked if it connects properly using an if statement and it returns true

Next time, could you please format your code as code in the forum post? If you don’t, the forum will try parsing it as markup, which could result in printed output that’s not actually valid code.

You code seems a bit off due to all the quotes being formatted. But I don’t know if that’s your code or the forum.

I tried to run the query in phpMyAdmin too, but there doesn’t appear to be a Section_Keys table, so it’s hard to check.

2 Likes

Sorry I changed the name of table thinking that the word keys is messing things up as it is a keyword in mysql

Here is the new code

$query='SELECT * FROM `Section_id`;' ;

$result=mysqli_query($conn,$query);


Does that query work in your code? Because it works in phpMyAdmin.

That’s the problem It works in phpmyadmin but shows the error ( got the error by using musqli_error() method ) when I run the exact code via code and I recently noticed that when I copy and paste a sql code to phpmyadmin it shows the same type of error like it says there I syntax error but actually there is not , I think it only accept sql generated by itself like when you press those select, insert, update etc. buttons it works well

I literally copy-pasted the query from your post here, and that also works.

Is it possible that some of the characters in your code are not what they seem? I’ve seen cases where people wrote code that looked like regular ASCII text, but some characters were mistyped and were some exotic special language characters which only look the same.

Could you maybe try re-typing the query?

4 Likes

I suspected that too , so I retyped the code several times and I scanned the query for any hidden character nd it turned out there is not , I have posted another problem with my account too about SSL issues , do you think the problem is with my account ? Cause I suspect that.

I am uploading my whole script here maybe someone can figure something out
verifySection.php (318 Bytes)

Your code has some odd formatting.

SELECT * FROM Section_id

Also, your query doesn’t need a semicolon in PHP.

4 Likes

The code is not finished I just want to make sure that the basic code runs fine so that I can actually do some work, And is that  causing the problems I don’t know where it came from, maybe it’s because I typed it from my mobile

If you just copy-paste what I typed above, you should be fine. I typed it from my mobile as well.

5 Likes

Man thanks a lot it worked , I think as admin mentioned there was some hidden character in my query, I am marking yours as answer thanks man.

3 Likes

@Lone_Wolf You are quite welcome! I’m glad I could help you!

4 Likes

Now on I will try to use a proper a code editor so that I can avoid these issues, anyways thanks again

1 Like

In VS Code
image

4 Likes

Thanks man I will look out for it

1 Like