Почему я не могу вставить данные в свою базу данных?
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. :)
Что я уже пробовал:
Я попытался использовать процедурный метод mysqli
$servername = " localhost";
$username = " имя пользователя";
$password = " пароль";
$dbname = " myDB";
// Создать соединение
$Конн = mysqli_connect($имя_сервера, $имя пользователя, $пароль $имя_бд);
// Проверить соединение
если (! $conn) {
die ("ошибка подключения:". mysqli_connect_error());
}
// sql для создания таблицы
$sql = " создать таблицу MyGuests (
id INT(6) unsigned AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
фамилия VARCHAR (30) NOT NULL,
электронная почта VARCHAR(50),
отметка времени reg_date
)";
if (mysqli_query($conn, $sql)) {
echo " таблица MyGuests успешно создана";
} еще {
echo " Error creating table:". mysqli_error($conn);
}
mysqli_close($Конн);
?>