Report this

What is the reason for this report?

Uploading file/data using PHP and MYSQL not working

Posted on May 17, 2021

Hi there, this is probably a basic question but I cannot find the answer on google and StackOverflow

I already install the PHP and MYSQL in my droplet. Displaying data from my database is working, I can able to display the data from my database on my website, and even update query, and delete query using PHP and MYSQL. But the problem is, adding data is not working.

Here’s my test code

<?php
$db = mysqli_connect("localhost", "xxxx", "XXXXX", "xxxxx");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}

$admin_accounts = mysqli_query($db, "SELECT * FROM admin_accounts");

while ($row = mysqli_fetch_array($admin_accounts)) {
	echo "<br />" . $row['email'];
}

mysqli_query($db, "INSERT INTO admin_accounts (email) VALUES ('testtest@gmail.com'); ");

?>

INSERT INTO query is not working but I tested the UPDATE query and DELETE query it’s working, please help me out of this problem.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @micronicsphils,

It sounds like that your MySQL user does not have insert privileges.

You could try granting all privileges for the MySQL user that you are using to the MySQL database that you are using:

GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_user'@'%' WITH GRANT OPTION;

Let me know how it goes! Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.