Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Why MySQLi insert query not working Ubuntu

Writer Matthew Martinez

Hi there I'll be glad if anyone has answer to this question, i recently change my pc os to Ubuntu and also download Xampp on it, but the problem now is PHP MYSQLI insert query not working on my pc, all the website i developed before, am unable to register on any of it on my pc localhost,

this site is on running on a lamp server... i initially noticed that there was a problem registering new account and adding new content to the website, I spent a long time trying to figure what could have happened to my code but i can't figure it out.

I using lampp for Ubuntu i downloaded from , and i use the command line below to install it

$ chmod 755 xampp-linux-x64-7.3.31-3-installer.run

$ ls -l xampp-linux-x64-7.3.31-3-installer.run

$ sudo ./xampp-linux-x64-7.3.31-3-installer.run

am runing the code below but am not getting any error message and the values are not inserted into the database, i also noticed if i creat a new database table, with just 2 columns id and fname, the values will be inserted but once the table columns is more than 2 it wont insert again also i cant register on my previous project database i imported to my lampp phpmyadmin

here is the code

<?php
// all db connections is declear here
$servername = "localhost";
$dBUsername = "root";
$dbPassword = "";
$dBName = "crypto";
$conn = mysqli_connect($servername, $dBUsername, $dbPassword,
$dBName);
if(!$conn){
echo "Database Connection Failed";
exit();
}
// insert into database
$RegS="INSERT INTO user_info (`fname`) VALUES('user')";
$RegR = mysqli_query($conn, $RegS);
if ($RegR == TRUE) {
echo'Successfull';
}
?>

I'll be glad if anyone can be of help.

2

1 Answer

The root MySQL account cannot be used for web applications anymore. The only time the root MySQL account should be used is when:

  1. the database is being set up for the first time
  2. you are performing administrative tasks
  3. you are fixing something that has gone really, really wrong

Instead, you will need to create a new MySQL user and grant it access to the database. Here's how:

  1. From the Terminal (or SSH connection), connect to MySQL as the root user via sudo:
    sudo mysql 
  2. Create a new MySQL user:
    CREATE USER 'coins'@'localhost' IDENTIFIED WITH mysql_native_password BY 'superSecretPassword!123';
    Note: Be sure to replace coins and superSecretPassword!123 with whatever you'd like.
  3. Grant access to the database:
    GRANT ALL ON `crypto`.* TO 'coins'@'localhost';

From here, you can update your PHP file for the new username and password and see things work as expected.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy