Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HTML
Hi everyone!, I need your help please. I can't able to insert my data info into my database. I already created database in phpmyadmin.

Please check may codes below: 

<------donation form code---------->

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Donation Form</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
input[type=submit] {
    width: 100%;
    background-color: #008000;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #45a049;
}

</style>
</head>
<body> 
<div class="container">
  <div class="btn-group btn-group-justified">
    <a href="donationform.php" class="btn btn-success">Donate</a>
    <a href="volunteerform.php" class="btn btn-warning">Volunteer</a>
</div>
<br><center><p>Make an online donation to help us, care and support services to the needy. Please submit your donation form below.</p></center>
<div>
  <form class="form-horizontal" role="form">
<div class="container">
  <h2>DONATION FORM</h2><br>
  <form action="insert.php" method="post">
    <div class="form-group">
      <label class="control-label col-sm-2" for="fname">Donor Full-Name: </label>
      <div class="col-sm-10">
        <input type="text" name="fname" class="form-control" placeholder="Enter Your Full-Name">
      </div>
    </div>
 <form class="form-horizontal" role="form">
  <div class="form-group">
     <label class="control-label col-sm-2" for="usedonation">Use my donation for:</label>
     <div class="col-sm-10">
      <select name="donation for" class="form-control">
        <option>Disaster Victims</option>
        <option>Local Community</option>
        <option>Home visits for medical patients</option>
        <option>Environmental (Recyling)</option>
        <option>for Events</option>
      </select>
    </div>
  </form>
</div>
    <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="amount">Donation amount ₱: </label>
      <div class="col-sm-10">
        <input type="text" name="amount" class="form-control" placeholder="Enter Your Donation Amount">
      </div>
    </div>
    <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="card number">Card number: </label>
      <div class="col-sm-10">
        <input type="text" name="card number" class="form-control" placeholder="Enter Your Card Number ">
      </div>
    </div>
    <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="account number:">Account number: </label>
      <div class="col-sm-10">
        <input type="text" name="account number" class="form-control" placeholder="Enter Your Account Number ">
      </div>
    </div>
    <form class="form-horizontal" role="form">
  <div class="form-group">
     <label class="control-label col-sm-2" for="preference">Donation Preference: </label>
     <div class="col-sm-10">
      <select name="preference" class="form-control">
        <option>One time donation</option>
        <option>Donate every month</option>
        <option>Donate every 3 months</option>
        <option>Donate every year</option>
      </select>
    </div>
  </form>
</div>
<form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Email: </label>
      <div class="col-sm-10">
        <input type="email" name="email" class="form-control" placeholder="Enter Your Email Address">
      </div>
    </div>
    <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="c-address">Current Address: </label>
      <div class="col-sm-10">
        <input type="c-address" name="address" class="form-control" placeholder="Enter Your Current Address">
      </div>
    </div>
     <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="contact number">Telephone/Cell number </label>
      <div class="col-sm-10">
        <input type="contact number" name="number" class="form-control" placeholder="Enter Your Contact Number">
      </div>
    </div><br>
    <div class="container">
      <form class="form-horizontal" role="form">
    <div class="form-group">
    <label for="comment">Note: </label>
      <textarea class="form-control" name="comment" rows="5" name="comments" placeholder="Type your message for us" required></textarea>
    </div>
  </form>
</div><br><br><br><br>
  <input type="submit" value="DONATE">
      </div>
    </div>
  </form>
</div>
</div>
</body>
</html>

<------------insert database code----------->


 <html>
 <body>

 <?php
$servername = "localhost";
$username = "root";
$password = "butipayunghanginnagpaparamdam";
$dbname = "donation";

// Create connection
$conn = new mysqli($localhost, $root, $butipayunghanginnagpaparamdam, $donation);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO donation_form (donor fname, donation for, donation amount, card number, account number, preference, email, address, contact number, note)
VALUES 
('fname','donation for','amount','card number','account number','preference','email','address','number','comment')";


if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?> 

</body>
</html>


Please help me in my website project thank you so much in advance. :)


What I have tried:

I tried to used mysqli procedural method


$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}

mysqli_close($conn);
?>
Posted
Updated 11-Jul-16 17:43pm

1 solution

The INSERT query seems weird, the column names particularly. If you have typed correct coulmn names for donation_form table then consider following suggestions-

1. Your column names should not contain blank spaces but if you have such column names then wrap them in square brackets as follows-
PHP
$sql = "INSERT INTO donation_form ([donor fname], [donation for], [donation amount], [card number], [account number], [preference], [email], [address], [contact number], [note])
VALUES 
....
....

2. I belive, amount column must be of numeric/money data type but you have given string value in VALUES list.

Correct these first and check if it works. If you still finding more issues, please let me know.

Hope, it helps :)
 
Share this answer
 
Comments
Jireh Capao 12-Jul-16 2:46am    
Yes!, amount column set numeric data type. I don't know what is wrong?. Why may data info in my forms field can't store data in my database?. :'(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900