У меня проблема с тем, что этот код не вставляет значения в базу данных ...
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
//including the database connection file
include("config.php");
if (isset($_POST['Submit'])) {
$sitenumber = $_POST['sitenumber'];
$videolink = $_POST['videolink'];
$daynight = $_POST['daynight'];
$maxtents = $_POST['maxtents'];
$maxpersons = $_POST['maxpersons'];
$geography = $_POST['geography'];
$view = $_POST['view'];
$forestcover = $_POST['forestcover'];
$waterfront = $_POST['waterfront'];
$firepit = $_POST['firepit'];
$description = $_POST['description'];
$reslink = $_POST['reslink'];
// checking empty fields
if (empty($sitenumber) || empty($videolink) || empty($daynight) || empty($maxtents) || empty($maxpersons) || empty($geography) ||
empty($view) || empty($forestcover) || empty($waterfront) || empty($firepit) || empty($description) || empty($reslink)) {
if (empty($sitenumber)) {
echo "<font color='red'>Site Number field is empty.</font><br/>";
}
if (empty($videolink)) {
echo "<font color='red'>YouTube Link field is empty.</font><br/>";
}
if (empty($daynight)) {
echo "<font color='red'>Day or Overnight field is empty.</font><br/>";
}
if (empty($maxtents)) {
echo "<font color='red'>Maximum Tents field is empty.</font><br/>";
}
if (empty($maxpersons)) {
echo "<font color='red'>Maximum Persons field is empty.</font><br/>";
}
if (empty($geography)) {
echo "<font color='red'>Geography field is empty.</font><br/>";
}
if (empty($view)) {
echo "<font color='red'>View field is empty.</font><br/>";
}
if (empty($forestcover)) {
echo "<font color='red'>Forest Cover field is empty.</font><br/>";
}
if (empty($waterfront)) {
echo "<font color='red'>Waterfront Access field is empty.</font><br/>";
}
if (empty($firepit)) {
echo "<font color='red'>Firepit field is empty.</font><br/>";
}
if (empty($description)) {
echo "<font color='red'>Description field is empty.</font><br/>";
}
if (empty($reslink)) {
echo "<font color='red'>Reservation Link field is empty.</font><br/>";
}
//link to the previous page
echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
} else {
// if all the fields are filled (not empty)
//insert data to database
$result = mysqli_query($mysqli, "INSERT INTO sites (sitenumber,videolink,daynight,maxtents,maxpersons,geography,view,forestcover,waterfront,firepit,description)
VALUES ('{$sitenumber}','{$videolink}','{$daynight}','{$maxtents}','{$maxpersons}','{$geography}','{$view}','{$forestcover}','{$waterfront}','{$firepit}','{$description}')");
//display success message
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='index.php'>View Result</a>";
}
}
?>
</body>
</html>
Я не могу понять ... Я убедился, что значения передаются со страницы HTML-формы. Мне удалось заставить страницу удаления работать нормально. Mysqli_query (insert into) просто не вставляет значения в базу данных.
Вы можете попробовать echo mysqli_error($mysqli); после вашего оператора вставки, чтобы узнать, есть ли в вашем запросе ошибка.






ЕСЛИ ваш ЕЩЕ работает, а ваш Подключение MYSQL работает, чем будет запрос.
mysqli_query($mysqli, "INSERT INTO sites(
`sitenumber`,
`videolink`,
`daynight`,
`maxtents`,
`maxpersons`,
`geography`,
`VIEW`,
`forestcover`,
`waterfront`,
`firepit`,
`description`
)
VALUES(
'$sitenumber',
'$videolink',
'$daynight',
'$maxtents',
'$maxpersons',
'$geography',
'$view',
'$forestcover',
'$waterfront',
'$firepit',
'$description'
)";
Просто хотел ответить, что я понял это благодаря echo mysqli_error ($ mysqli), и это довольно сумасшедший. Я просто не вставил повторную ссылку во вставку, и, поскольку я не назначил ей значение по умолчанию, он останавливался на этом. Как только я добавил в запрос, все заработало.
Достигает ли ваш код оператора вставки?