0
이는 index.php 파일입니다 :PHP를 사용하여 mysql 데이터베이스에 값을 추가 할 수 없습니까?
<?php
//Attempt MySQL server connection. Assuming you are running MySQL
//server with default setting (user 'root' with no password)
$link = mysqli_connect("localhost", "root", "SecretPassword", "ClientDataDB");
// Check connection
if($link === false){
die("Connection failed: " . mysqli_connect_error());
}
// Attempt select query execution
$sql = "SELECT * FROM ClientLogin";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>First Name</th>";
echo "<th>Last Name</th>";
echo "<th>Email</th>";
echo "<th>Username</th>";
echo "<th>Password</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Username'] . "</td>";
echo "<td>" . $row['Password'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Close result set
mysqli_free_result($result);
} else{
echo "No records found!";
}
} else{
echo "Error could not execute query: " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
<head>
<meta charset="UTF-8">
<title>Create New User</title>
</head>
<body>
<form action="insert.php" method="post">
<p>
<label>First Name:</label>
<input type="text" name="FirstName"/>
</p>
<p>
<label>Last Name:</label>
<input type="text" name="LastName"/>
</p>
<p>
<label>Email Address:</label>
<input type="text" name="Email"/>
</p>
<p>
<label>Username:</label>
<input type="text" name="Username"/>
</p>
<p>
<label>Password:</label>
<input type="text" name="Password"/>
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
그리고 이것은 insert.php 파일입니다
<?php
//Attempt MySQL server connection. Assuming you are running MySQL
//server with default setting (user 'root' with no password)
$link = mysqli_connect("localhost", "root", "MiggKuter5049", "ClientDataDB");
//Check connection
if($link === false)
{
die("Connection failed: " . mysqli_connect_error());
}
//Get user inputs
$firstname = $_POST['FirstName']);
$lastname = $_POST['LastName']);
$email = $_POST['Email']);
$username = $_POST['Username']);
$password = $_POST['Password']);
// attempt insert query execution
$sql = "INSERT INTO ClientLogin (FirstName, LastName, Email, Username, Password) VALUES ('$firstname', '$lastname', '$email', '$username', '$password')";
if(mysqli_query($link, $sql)){
echo "User added successfully!";
} else{
echo "Error, could not execute query: " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
나는 내 인생 내 실수를 찾을 수 없습니다. 제출 단추를 누르면 표에 다른 항목이 작성되지만 모두 공백으로 입력 된 값은 사용되지 않습니다. 제발 도와주세요 :)
추가 인 print_r ($ _ POST)처럼 보일 것입니다. –
지금 내가 제출할 항목을 클릭하면 수신 : 192.168.1.103 페이지가 작동하지 않습니다. 192.168.1.103이 (가)이 요청을 처리하지 못했습니다. HTTP 오류 500 –