У меня есть форма, которая, как представляется, связана с базой данных mysql. Когда я вводим информацию в форму и отправляю ее, она регистрируется в базе данных как «0000-00-00», и данные возвращаются как «0000-00-00». Ни одна из фактических данных не появляется. Есть идеи?Как получить правильные данные при сохранении в базе данных mysql?
connection.php:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$db = 'sm_residents';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
?>
create.php:
<?php
include ('connection.php');
$FirstName= $_POST['inputFirstName'];
$LastName= $_POST['inputLastName'];
$Address= $_POST['inputAddress'];
$Birthday= $_POST['inputBirthday'];
$FormerResidence= $_POST['inputFormerResidence'];
$Career= $_POST['inputCareer'];
$Education= $_POST['inputEducation'];
$SpecialInterests= $_POST['inputSpecialInterests'];
if ($_FILES["file"]["error"] > 0) {
} else {
if (file_exists("upload/" . $_FILES["file"]["name"])) {
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
}
}
Picture= $_FILES["file"]["name"];
mysql_query("INSERT INTO residents (`ID`,`FirstName`,`LastName`,`Address`,`Birthday`,`FormerResidence`,`Career`,`Education`,`SpecialInterests`,`Picture`)
VALUES(NULL,'$FirstName','$LastName','$Address','$Birthday','$FormerResidence','$Career','$Education','$SpecialInterests','$Picture')") or die(mysql_error());
?>
<script> window.location = "index.php"; </script>
Index.php:
<?php
include ('connection.php');
if(isset($_POST['submit'])) {
echo "Please Fill Out The Form";
//header ('Location: create.php');
} else {
//echo "User Has Been Added";
//header('Location: create.php');
}
?>
<h1>Add A Resident</h1>
<form action="create.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="inputFirstName">First Name</label>
<input type="text" class="form-control" id="inputFirstName" placeholder="First Name">
</div>
<div class="form-group">
<label for="inputLastName">Last Name</label>
<input type="text" class="form-control" id="inputLastName" placeholder="Last Name">
</div>
<div class="form-group">
<label for="inputAddress">Address</label>
<input type="text" class="form-control" id="inputAddress" placeholder="Address">
</div>
<div class="form-group">
<label for="inputBirthday">Birthday</label>
<input type="date" class="form-control" id="inputBirthday">
</div>
<div class="form-group">
<label for="inputFormerResidence">Former Residence</label>
<input type="text" class="form-control" id="inputFormerResidence" placeholder="Former Residence">
</div>
<div class="form-group">
<label for="inputCareer">Career</label>
<input type="text" class="form-control" id="inputCareer" placeholder="Career">
</div>
<div class="form-group">
<label for="inputEducation">Education</label>
<input type="text" class="form-control" id="inputEducation" placeholder="Education">
</div>
<div class="form-group">
<label for="inputSpecialInterests">Special Interests</label>
<input type="text" class="form-control" id="inputSpecialInterests" placeholder="Special Interests">
</div>
<div class="form-group">
<label for="inputFile">File input</label>
<input type="file" id="inputFile">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Каких переменный в коде вы работаете? – pareto
Вам не хватает '$' перед 'Picture ='. Как это работает? – Barmar
У вас нет элемента формы ввода с именем 'submit', поэтому я не знаю, как это работает даже если if (isset ($ _ POST ['submit'])) { echo« Пожалуйста, заполните форму »; не имеет смысла. Плюс это 'Picture = $ _FILES [" file "] [" name "];' это опечатка? Если нет, добавьте '' '' 'Picture' -' $ Picture = $ _FILES ["file"] ["name"]; '- Если ваши данные выходят как нули, проверьте тип столбца. –