Я пытаюсь создать простую html-форму, которая хранит информацию через MySQL, но у меня есть некоторые проблемы с подключением к базе данных. Я думаю, что $ db_selected = mysql_select_db (DB_NAME, $ link); дает мне проблему. FYI DB_NAME - это таблица базы данных, которую я хочу использовать.
Мой HTML
<form action="demo.php" method="post">
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" class="form-control" id="firstname" name="first_name">
</div>
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" class="form-control" id="lastname" name="last_name">
</div>
<div class="form-group">
<label for="dob">Date of birth:</label>
<input type="password" class="form-control" id="dob" name="date_of_birth">
</div>
<div class="form-group">
<label for="pob">Place of birth:</label>
<input type="text" class="form-control" id="pob" name="place_of_birth">
</div>
<div class="form-group">
<label for="government">Your Local government:</label>
<input type="text" class="form-control" id="government" name="government">
</div>
<div class="form-group">
<label for="qualifications">Qualifications:</label>
<textarea class="form-control" rows="5" id="qualifications" name="qualifications"></textarea>
</div>
<div class="form-group">
<label for="skills">Skills:</label>
<textarea class="form-control" rows="5" id="skills" name="skills"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Мой PHP
<?php
define('DB_NAME', 'forms1');
define('DB_USER', 'c88888');
define('DB_PASSWORD', '*******');
define('DB_HOST', 's********.com');
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db_selected = mysqli_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysqli_error());
}
$value = $_POST['first_name'];
$value2 = $_POST['last_name'];
$value3 = $_POST['date_of_birth'];
$value4 = $_POST['place_of_birth'];
$value5 = $_POST['government'];
$value6 = $_POST['qualifications'];
$value7 = $_POST['skills'];
$sql = "INSERT INTO demo (first_name, last_name, date_of_birth, place_of_birth, government, qualifications, skills) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7')";
if (!mysqli_query($sql)) {
die('Error: ' . mysqli_error());
}
mysqli_close();
?>
Я пытаюсь создать простую html-форму, которая хранит информацию через MySQL, но у меня есть некоторые проблемы с подключением к базе данных. Я думаю, что $ db_selected = mysql_select_db (DB_NAME, $ link); дает мне проблему. FYI DB_NAME - это таблица базы данных, которую я хочу использовать.
Мой HTML
<form action="demo.php" method="post">
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" class="form-control" id="firstname" name="first_name">
</div>
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" class="form-control" id="lastname" name="last_name">
</div>
<div class="form-group">
<label for="dob">Date of birth:</label>
<input type="password" class="form-control" id="dob" name="date_of_birth">
</div>
<div class="form-group">
<label for="pob">Place of birth:</label>
<input type="text" class="form-control" id="pob" name="place_of_birth">
</div>
<div class="form-group">
<label for="government">Your Local government:</label>
<input type="text" class="form-control" id="government" name="government">
</div>
<div class="form-group">
<label for="qualifications">Qualifications:</label>
<textarea class="form-control" rows="5" id="qualifications" name="qualifications"></textarea>
</div>
<div class="form-group">
<label for="skills">Skills:</label>
<textarea class="form-control" rows="5" id="skills" name="skills"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Мой PHP
<?php
define('DB_NAME', 'forms1');
define('DB_USER', 'c88888');
define('DB_PASSWORD', '*******');
define('DB_HOST', 's********.com');
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db_selected = mysqli_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can't use ' . DB_NAME . ': ' . mysqli_error());
}
$value = $_POST['first_name'];
$value2 = $_POST['last_name'];
$value3 = $_POST['date_of_birth'];
$value4 = $_POST['place_of_birth'];
$value5 = $_POST['government'];
$value6 = $_POST['qualifications'];
$value7 = $_POST['skills'];
$sql = "INSERT INTO demo (first_name, last_name, date_of_birth, place_of_birth, government, qualifications, skills) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7')";
if (!mysqli_query($sql)) {
die('Error: ' . mysqli_error());
}
mysqli_close();
?>
00PHP, HTML, MySQL,