Arci Arci - 1 year ago 101
MySQL Question

How do you connect bootstrap form to database

I have created a bootstrap form ,but it won't connect to the database. After filling up the forms, it gives me an undefined index error. I have no idea what to do. Can you help me? I'm so lost.

<form name="input" method="post" action="addtodatabase.php">

<div class="form-group">
<label for="Book_Number">Book Number</label>
<input type="text" class="form-control" id="Book_Number" placeholder="Enter Book Number">

<div class="form-group">
<label for="Book_Title">Book Title</label>
<input type="text" class="form-control" id="Book_Title" placeholder="Enter Book Title">

<div class="form-group">
<label for="Book_Description">Book Description</label>
<input type="text" class="form-control" id="Book_Description" placeholder="Enter Book Description">

<div class="form-group">
<label for="Author">Author</label>
<input type="text" class="form-control" id="Author" placeholder="Enter Author">

<div class="form-group">
<label for="Publisher">Publisher</label>
<input type="text" class="form-control" id="Publisher" placeholder="Enter Publisher">

<div class="date">
<label for="Year_Published">Year Published</label>
<input type="date" class="form-control" id="Year_Published" placeholder="Enter Year Published">

<input type="submit"> <input type="reset"></center>

The undefined index error refers to Book_Number etc.

$connection = mysql_connect ('localhost','root','');

$Book_Number = $_POST ['Book_Number'];
$Book_Title = $_POST ['Book_Title'];
$Book_Description= $_POST['Book_Description'];
$Author = $_POST ['Author'];
$Publisher = $_POST['Publisher'];
$Year_Published = $_POST['Year_Published'];

$query =
"INSERT INTO Theology_Books


('$Book_Number','$Book_Title','$Book_Description','$Author','$Publisher','$Y ear_Published')";

$result = mysql_query($query);
Echo "Database Saved";

Answer Source

With forms to send data to the next page your inputs need to have the name attribute. try changing the id = 'book_number' to name = 'book_number'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download