私は、データベースにアーティスト、アルバム、および曲を追加して議論することができる音楽ウェブサイトを作成しています。ただし、ユーザーがサインアップフォームに入力したデータをデータベースの「ユーザー」テーブルに転送することはできません。私は何が間違っているのか正確には分かっていませんが、データベースの接続に問題がないため、構文に問題があると思われます。私は何時間も探していますが、私はまだ解決策を見つけていません。誰でも助けてくれますか?PHPを使用してMySQLデータベースにデータを挿入できません
<?php include 'header.php'; ?>
<form class="form" action="register.php" method="POST">
<fieldset>
<label for="firstName">First Name:</label>
<input type="text" name="firstName" placeholder="John Smith">
<br>
<label for="lastName">Last Name:</label>
<input type="text" name="lastName" placeholder="John Smith">
<br>
<label for="email">Email:</label>
<input type="email" name="email" value="[email protected]">
<br>
<label for="username">Username:</label>
<input type="text" name="username" value="helloitsme">
<br>
<label for="password">Password:</label>
<input type="password" name="password">
<br>
<label for="confirmPassword">Confirm Password:</label>
<input type="password" name="confirmPassword">
<br>
<label for="age">Age:</label>
<input type="number" name="age">
<br>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="Register">
</fieldset>
</form>
register.php:エラーは、ユーザーが
signup.phpを「提出」ヒットの後にサインアップフォームからの情報のどれもが私のデータベースに入力されていない取得されていることである。明確にするために
:
<?php
session_start();
if ($_POST["password"] != $_POST["confirmPassword"]) {
$_SESSION['signUpBadPassword'] = true;
header('Location: signup.php');
}
// Re use connection stuffs
include "db.php";
// get connection
$conn = DB::connect();
$stmt = $conn->prepare("INSERT INTO users (firstName, lastName, email, username, password, age) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param(
"sssssi",
$_POST["firstName"],
$_POST["lastName"],
$_POST["email"],
$_POST["username"],
$_POST["password"],
$_POST["age"]
);
$stmt->execute();
// Close the connection
$conn->close();
header('Location: index.php');
?>
とをdb.php:
<?php
class DB
{
public static function connect()
{
$hostname = 'localhost';
$username = 'user';
$password = 'password';
$dbName = 'dbname';
$connection = new mysqli($hostname, $username, $password, $dbName);
if ($connection->connect_error) {
die('Failed to connect');
}
return $connection;
}
}
エラーは何ですか? – Talhiner
エラーが生じましたか? –
申し訳ありませんが、私は十分に明確ではありませんでした。エラーは、サインアップフォームに「提出」した後、データがミュージックデータベースに挿入されていないことです。 –