-4
<?php
if(isset($_POST['submit'])){
$data_missing = array();
if(empty($_POST['first_name'])){
// Adds name to array
$data_missing[] = 'First Name';
} else {
// Trim white space from the name and store the name
$f_name = trim($_POST['first_name']);
}
if(empty($_POST['last_name'])){
// Adds name to array
$data_missing[] = 'Last Name';
} else{
// Trim white space from the name and store the name
$l_name = trim($_POST['last_name']);
}
if(empty($_POST['email'])){
// Adds name to array
$data_missing[] = 'Email';
} else {
// Trim white space from the name and store the name
$email = trim($_POST['email']);
}
if(empty($_POST['birth_date'])){
// Adds name to array
$data_missing[] = 'Birth Date';
} else {
// Trim white space from the name and store the name
$b_date = trim($_POST['birth_date']);
}
if(empty($_POST['sex'])){
// Adds name to array
$data_missing[] = 'Sex';
} else {
// Trim white space from the name and store the name
$sex = trim($_POST['sex']);
}
if(empty($data_missing)){
require_once('database.php');
$query = "INSERT INTO etable (first_name, last_name, email,
birth_date, sex) VALUES (?, ?, ?,
?, ?, ?)";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "ssssss", $f_name,
$l_name, $email, $b_date,
$sex);
mysqli_stmt_execute();
$affected_rows = mysqli_stmt_affected_rows();
if($affected_rows == 1){
echo 'Student Entered';
mysqli_stmt_close($stmt);
mysqli_close($dbc);
} else {
echo 'Error Occurred<br />';
echo mysqli_error($dbc);
mysqli_stmt_close($stmt);
mysqli_close($dbc);
}
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
Bitte siehe [fragen] und [Die perfekte Frage] (http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). – Rizier123
Zählen Sie Ihre Spalten. –
@ Fred-ii- Hmm, ich habe so ziemlich das Gleiche geschrieben, aber als Antwort. Habe ich falsch gemacht? –