Failed to Insert data into database please help

Username: epiz_29160986

(please specify the website or account you are asking about)

There is connection but data failed inserted into database I get an error message

Error Message

These are my codes…

<?php include_once("db.php"); if (isset($_POST['submit'])) { // code... $username = $_POST['username']; $password = md5($_POST['password']); } //if all field are filled no empty field $query = "INSERT INTO users(username, password) VALUES('$username','$password');"; $run = mysqli_query($conn, $query); //Check if data is inserted into Database if (!$run) { echo "Error : cannot add to database: ".mysqli_errno($conn); } else { echo"No Problem"; } ?>

(please share the FULL error message you see)

I get an error said

Error : cannot add to database: 1046

Hey, this topic is similar to I cannot insert data into my database via a php code - #3 by SWIPHY

yes I saw but I was able to solve the problem… can you help me?

Wait, so is it working or not?

Error code 1046 means “No database selected”. This could mean a missing property in setting up the database connection, but your code doesn’t show that part. Could you please share db.php too (without passwords and other sensitive details of course) so we can verify the database is selected correctly?

Also, could you please format your post correctly? You can use HTML, BBCode or Markdown, and it makes code a lot easier to read.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.