gpt4 book ai didi

php - 为什么我的 PHP 总是出现 500 错误?

转载 作者:行者123 更新时间:2023-11-29 05:35:10 24 4
gpt4 key购买 nike

我正在尝试创建一个帐户注册页面,当我添加一个系统来检查数据库并确保没有多个行具有相同的用户名时,我收到了 500 错误。

这是有效的代码:

<?php


if(isset ($_POST['submit']))
{
include( 'connection.php' );

$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

if(empty($username) || empty($email) || empty($password))
{
echo 'Please check the required fields.';
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL))
{
echo 'Please enter a correct email address.';
}
else
{
$password = md5($password);
$sql = mysql_query("INSERT INTO users (email,username,password) VALUES ('$email','$username','$password')") or die(mysql_error());

if($sql)
{
echo 'Successfully submitted.';
}
}
}
?>

这是给我一个 500 错误的代码:

<?php
error_reporting(E_ALL)

if(isset ($_POST['submit'])) {
include( 'connection.php' );

$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

$fetch = mysql_query("SELECT * FROM users WHERE username = '$email'") or die(mysql_error();
$num_rows = mysql_num_rows($fetch);

if(empty($username) || empty($email) || empty($password)) {
echo 'Please check the required fields.';
}
elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
echo 'Please enter a correct email address.';
}

elseif($num_rows >= 1);
{
echo 'This username is taken.';

else
}
$password = md5($password);
$sql = mysql_query("INSERT INTO users (email,username,password) VALUES ('$email','$username','$password')") or die(mysql_error());

if($sql)
{
echo 'Successfully submitted.';
}
}
}
?>

最佳答案

也许加一个分号:

error_reporting(E_ALL);

编辑:

你还缺少一个 ) on die(mysql_error();

elseif($num_rows >= 1); 中删除 ;

然后将您的 else block 修改为 } else {

关于php - 为什么我的 PHP 总是出现 500 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379016/

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