gpt4 book ai didi

单击表单按钮时 PHP 服务器错误 500

转载 作者:行者123 更新时间:2023-11-29 11:44:25 25 4
gpt4 key购买 nike

当我在表单中选择带有登录处理页面链接的按钮时,它只返回服务器错误 500,我以前没有遇到过这种情况,而且在 google 上也没有运气。

这是我在登录页面上的 HTML 标记

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Administrator Login</title>
</head>

<body>
<div class="container">
<div class="header"><a href="index.php"><img src="IMAGES/LOGO.png" alt="Insert Logo Here" name="Insert_logo" width="" height="90" id="Insert_logo" style="background-color: #; display:block;" /></a>
<!-- end .header --></div>
<div class="content">
<form action="loginProcess.php" method="post" class="loginForm">
<input type="text" id="username" name="username" placeholder="Enter Username" required>
<input type="password" id="password" name="password" placeholder="Enter Password" required>
<button type="submit" id="loginBTN" >Login</button>
</form>
</div>

</body>
</html>

这是我的 php 进程的代码

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);

//stores the search data
$username = $_POST['username'];
$password = $_POST['password'];

//checks to see if it is empty or null
if(isset($username) && !empty($username) && (isset($password) && !empty($password))){
require('includes/dbconx.php');

//escapes all special characters that could break database

$pword = mysqli_real_escape_string($con, $password);
$uname = mysqli_real_escape_string($con, $username);
//searchq stores the cleaned up search data

//create a variable to store a wildcard SQL statement

$sql = mysqli_query($con, "SELECT * FROM login WHERE username = '%$uname%' AND password = '%$pword%' ");
}//end statement

//if no data is inserted it will putput this
else{
echo("Please enter Login details!");

//this will kill the connection

die;
}
//end else
$result = $con->query($sql);
//if it finds no matching data it informs the user and kills the DB connextion
if(mysqli_num_rows($result) == 0){
echo("<p>No record found or password doesn't match! </p>");
die;
}
else{
header('Location: adminPage.php');

?>

</body>
</html>

这是我的连接,这适用于其他页面,因为它应该如此。

<?php
//connects to my music database
$con=mysqli_connect("localhost","root","root","music");
//if it fails to connect it outputs this with an error number
if(mysqli_connect_errno()) {
echo "failed to connet to MYSQL:".mysqli_connect_error();
}
?>

最佳答案

有时间喝啤酒吗?

此查询不正确,仅在使用 LIKE 语法时才使用 % 字符,因此查询应为

$sql = mysqli_query($con, "SELECT * 
FROM login
WHERE username = '$uname'
AND password = '$pword' ");

如果您的代码格式更加一致,也将有助于发现错误。

就像我对上一个问题的回答一样,在所有 mysqli_ 调用之后检查错误。在开发过程中,这会节省你很多时间,因为那是我们开发人员制作小波波的时候

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// this would be better at the top of the script
require('includes/dbconx.php');

// why do 2 steps when one would do
// also you have not checked these actually exist
// until the IF that follows these 2 lines
//$username = $_POST['username'];
//$password = $_POST['password'];

// empty() does an isset already so you only need the empty()
if( !empty($username) && !empty($password)){
$pword = mysqli_real_escape_string($con, $_POST['password']);
$uname = mysqli_real_escape_string($con, $_POST['username']);

$sql = mysqli_query($con, "SELECT *
FROM login
WHERE username = '$uname'
AND password = '$pword'");

// always check status after mysqli_query and other calls
// and at least output the error message
if ( $sql === FALSE ) {
echo mysqli_error($con);
exit;
}

} else {
echo("Please enter Login details!");
die;
}

$result = $con->query($sql);
if(mysqli_num_rows($result) == 0){
echo("<p>No record found or password doesn't match! </p>");
die;
} else {
header('Location: adminPage.php');
// header Location: shoudl always be followed by an exit;
// as header does not stop execution
exit;

} // add missing closing bracket
?>
</body>
</html>

关于单击表单按钮时 PHP 服务器错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com