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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.