Database connection undefined variable

goodday house, I need an assistance with this connection. i am having an issue. i created a database called squared in mysql and under it a table called register with 3 field. so i am trying to insert information through coding using php editor. but i am having undefined variable error. i have already created the forms in html.

$servername = "localhost";

//create connection
$conn = mysqli_connect($servername, $username, $password, $database);

//check connection
if (!$conn){
    die("connection failed: " . mysqli_connect_error());
echo "connected successfully";
//use $query or sql
// name, email and address are fields of your fields; test your table. $name, $email and $address are values collected from the form
$sql = "INSERT INTO register (name, email, address) VALUES ('$name','$email' , '$address')";
if (mysqli_query($conn, $sql)){
    echo "Newrecord created successfully";
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);


edit your post and add around your code to format it correctly

done. Please can anyone recommend for me good sites i can learn file handling, validation and database connection in php

Everything that could possibly be wrong with that code is there. Go to this link and learn how to use PDO.

Try for learning: they have a lot of books. You will have to pay, about $100 a year, but I think that will help you.

Sponsor our Newsletter | Privacy Policy | Terms of Service