B
B
Bionis2021-07-03 10:15:44
PHP
Bionis, 2021-07-03 10:15:44

The data from the form does not want to be sent to the database. What have I done wrong?

My code:

<?php
if (isset($_POST['inquiries'])) {
    $host = "localhost";
    $username = "root";
    $password = "";
    $database = "Owl"; //also added semi colon and what database name
    $conn = mysqli_connect($host, $username, $password, $database);

    if (mysqli_connect_errno($conn)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $name = mysqli_real_escape_string($conn,$_POST['name']); //I've added $conn inside mysqli_real_escape_string expected 1st param
    $surname = mysqli_real_escape_string($conn,$_POST['surname']);
    $number = mysqli_real_escape_string($conn,$_POST['number']);
    $email = mysqli_real_escape_string($conn,$_POST['email']);
    $date = date("Y-m-d");

    $password = md5($password);

    $sql = "INSERT INTO users (name, surname, number, email, sign_up_date) VALUES ('$name', '$surname', '$number', '$email', '$date')";
    $query = mysqli_query($conn, $sql); // I think this will add data in your database.

    if (!$conn) { //I change this from mysql_query($sql)
        die('Error: ' .mysqli_error());
    } else {
       echo "Entry added successfully";

       mysqli_close($conn); 
    }
  }
?>

Columns in phpmyAdmin:
60e00d8adfc3d415405458.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question