Dawoodkhan Dawoodkhan - 3 months ago 21
MySQL Question

Sql queries and image upload not working in registration form

I worked on another registration form and that also shows no error but this one still doesn't insert values into database:

<?php
//connection
include("connection.php");

$error = "";

//getting values
if(isset($_POST['submit'])){
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConfirm = $_POST['passwordConfirm'];

//getting image
$image = $_FILES['image']['name'];
$tmp_image = $_FILES['image']['tmp_name'];
$imageSize = $_FILES['image']['size'];


else{
//inserting values int0 table
$insertQuery = "INSERT INTO users(firstName, lastName, email, password, image) VALUES ('$firstName,'$lastName','$email','$password','$image')";

if(mysqli_query($con, $insertQuery)){
if(move_uploaded_file($tmp_image,"images/$image")){
$error = "You are successfully registered";
}
else{
$error = "Image is not uploaded";
}
}
}

}

?>

Answer

It's not inserting values because there's an error in your insert statement.

('$firstName,'$lastName','$email','$password','$image')";

should be

('$firstName','$lastName','$email','$password','$image')";