Skip to content
Advertisement

PHP (v5.6) Error Uncaught exception ‘mysqli_sql_exception’ with message ‘Access denied for user [closed]

I want to run the following query, but I’m trying to switch to a prepared statement. This is the query

INSERT INTO SPAM_Accounts (Email, Password, Provider, About) VALUES (‘$_POST[Email]’, ‘$_POST[Password]’, ‘$_POST[Provider]’, ‘$_POST[About]’)

I followed w3schools‘s tutorial and I wrote the following code:

Well, I tried it, and I got this error:

Fatal error: Uncaught exception ‘mysqli_sql_exception’ with message ‘Access denied for user ‘id14748631_n1coclouds’@’%’ to database ‘information_schema” in /storage/ssd3/631/14748631/public_html/spam-account/insert.php:27

Stack trace: #0 /storage/ssd3/631/14748631/public_html/spam-account/insert.php(27): mysqli->prepare(‘INSERT INTO SPA…’)

#1 {main} thrown in /storage/ssd3/631/14748631/public_html/spam-account/insert.php on line 27

I checked the line 27 and this is the code:

$stmt = $mysqli->prepare(“INSERT INTO SPAM_Accounts (Email, Password, Provider, About) VALUES (?, ?, ?, ?)”);

What I am doing wrong? I’m learning PHP and MySQL, so a good explained answer will help me understand the problem.

Notice: Undefined index: About in /storage/ssd3/631/14748631/public_html/spam-account/insert.php on line 93

And on the line 93 is the following code:

(‘$_POST[Email]’, ‘$_POST[Password]’, ‘$_POST[Provider]’, ‘$_POST[About]’)”;

Advertisement

Answer

Well I found the solution. All I had to do was to change from

$_POST[idk]

to

$_POST[‘idk’]

Credits: Taavi Tiitsu

Then I had to delete the last 3 lines, in my case

$stmt->close(); $con->close(); ?>

You only should close PHP if you are going to write some HTML immediately after. Other than that your PHP files should never end in

Credits: Dharman

And the last mistake was not adding the fourth parameter inside connection function (database name).

$mysqli = new mysqli($servername, $username, $password, $dbname);

You forgot to set the fourth parameter in new mysqli.

That page you linked has a $dbname variable which you are missing in

Credits: brombeer, Dharman

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement