vendredi 19 juillet 2019

why my insert query doesn't work in php and there is no error

I am developing a website and I have insert query but it doesn't work(it isn't insert the data in my database) even though there are no errors appeared ,I am using localhost XAMMP and i put the connection code in another page this is my connection code a and my insert code.I though the problem with the connection but it print the statement

<?php



 $dbhost="localhost";
$dbuser="root";
$dbpass="";
$db="Driving1";

$conn = new mysqli($dbhost, $dbuser, $dbpass, $db);

if($conn->connect_error){
echo "connection was failed ";
}
else{
    echo "connection made";
}

?>
<?php

session_start();


$username = "";
$email    = "";
$number   ="";
$password1=  "";
$password2=  "";
$errors = array(); 


 include 'conn.php';


 if (isset($_POST['submit'])) {

  $username = mysqli_real_escape_string($conn, $_POST['username']);
  $email = mysqli_real_escape_string($conn, $_POST['email']);
   $password1 = mysqli_real_escape_string($conn, $_POST['pass1']);
   $password2 = mysqli_real_escape_string($conn, $_POST['pass2']);
   $number = mysqli_real_escape_string($conn, $_POST['mobile']);


  if ($password1 != $password2) {
   array_push($errors, "The two passwords do not match");
  }


  $user_check_query = "SELECT * FROM Trainee WHERE name='$username' ";
 $result = mysqli_query($conn, $user_check_query);

  $user = mysqli_fetch_assoc($result);


  if ($user) { 
   if ($user['name'] === $username) {
     array_push($errors, "Username already exists");
     }


  }


  if (count($errors) == 0) {
$password = md5($password1);

$query = "INSERT INTO Trainee (email, name, password,number) 
         VALUES('$email','$username','$password','$number')";

$result1=mysqli_query($conn, $query);


$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
//header('location: index.php');

} }

?>




Aucun commentaire:

Enregistrer un commentaire