简体   繁体   中英

adding HTML form input to database

Kindly need assistance in my coding, I have a database named Books with table called OpenBooks I would like to add the html form which are user inputs into the table and echo confirmation.

<?php

    $Title = $_POST['Title'];
    $Author = $_POST['Author'];
    $Series = $_POST['Series'];
    $Price =$_POST['price'];

    //database connection

   $connection = mysqli_connect('localhost', 'root', '','books');
   if(!$connection){
      die("Database connection failed");
   }
   $query = "INSERT INTO OpenBooks(Title,Author,series,price)";
   $query .= " VALUES ('$Title', '$Author', '$series', '$price')";
   $result = mysqli_query($connection, $query);

}
?>
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
else {
    echo 'yay, done';
}

And you need $Price instead of price and rest of variables starting from capital letter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM