Score:0

Why MySQLi insert query not working Ubuntu

fr flag

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 https://www.apachefriends.org/download.html, 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.

vidarlo avatar
om flag
You'll have to include some more information about your configuration and problems to get any help. What did you install, how did you install it, what code are you running, and what error messages do you get? [Edit] your question to add this information
Christaiwo avatar
fr flag
Yes i just updated it
Score:0
in flag

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.

Christaiwo avatar
fr flag
Thanks for your reply i did create a new user and edit the db connection but am getting, mysqli_real_connect(): (hy000/1045): access denied for user 'userone'@'localhost' (using password: yes)
in flag
Is the MySQL database hosted on the same machine as the web server?
Christaiwo avatar
fr flag
Yes it's hosted on the same pc, but i already figured where i got it wrong, when creating the table i don't set the default to null on my window pc, but when i migrated it to Ubuntu the MySQL doesn't support it so i had to change all table default to null, thanks once again and i appreciate your response am glad.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.