gpt4 book ai didi

php - 插入MYSQL失败

转载 作者:行者123 更新时间:2023-11-30 00:06:46 26 4
gpt4 key购买 nike

它什么也没做?甚至不显示错误代码?注册表单位于同一文档中。我尝试过 $_POST 和 $_REQUEST。难道这就是问题所在吗?

if ( $_SERVER ['REQUEST_METHOD'] =='POST' )
{
require ($_SERVER['DOCUMENT_ROOT']. '/INCLUDES/USER_DB1%20CON.php ');
$errors = array() ;

if( empty ( $_POST[' first_name ' ] ))
{ $errors[] = 'Enter Your First Name.' ; }
else
{$fn = mysqli_real_escape_string($link, trim( $_REQUEST[ 'first_name' ] )); }

if( empty ( $_POST[ ' last_name ' ] ))
{ $errors[] = 'Enter Your Last Name.' ; }
else
{$ln = mysqli_real_escape_string($link, trim( $_REQUEST[ 'last_name' ] )) ; }

if( empty ( $_POST[' email ' ] ))
{ $errors[] = 'Enter Your Email Address.' ; }
else
{$e = mysqli_real_escape_string($link, trim( $_REQUEST[ 'email' ] )) ; }

if( empty ( $_POST[' first_name ' ] ))
{ $errors[] = 'Enter Your First Name.' ; }
else
{$fn = mysqli_real_escape_string($link, trim( $_REQUEST[ 'first_name' ] )) ; }

if( !empty ($_POST ['pass1'] ))

if ( $_POST[' pass1'] != $_POST ['pass2'] )
{ $errors [] = 'Passwords Do Not Match.' ;}
else
{$p = mysqli_real_escape_string($link, trim($_REQUEST['pass1'] )) ; }
}
else { $errors[] = 'Enter A Password.' ; }

if ( empty ($errors ))

$q = "SELECT user_id FROM users WHERE email='$e'" ;
$r = mysqli_query ( $link , $q ) ;
if ( mysqli_num_rows($r) != 0 )
{ $errors[] = ' Email Address Already Registered. <a href=" ">Log In Here</a> ' ; }

if ( empty ($errors ))
{
$q = "INSERT INTO 'users'
(first_name, last_name, email, pass, reg_date)
VALUES ('$fn','$ln','$e', SHA1('$p'), NOW() ) " ;
$r = mysqli_query ( $link, $q) ;

if ( $r )
{
echo'<h1>Registered</h1>
<p>Log In <a href=" "> Here </a></p>' ;
}

mysqli_close( $link) ;
exit() ;

}

我已经尝试了我能想到的一切,它可能真的很简单,而且就在我面前。

最佳答案

尝试替换这个:

  if ( empty ($errors ))

$q = "SELECT user_id FROM users WHERE email='$e'" ;
$r = mysqli_query ( $link , $q ) ;
if ( mysqli_num_rows($r) != 0 )
{$errors[] = ' Email Address Already Registered. <a href=" ">Log In Here</a> ' ; }

if ( empty ($errors ))
{
$q = "INSERT INTO 'users'
(first_name, last_name, email, pass, reg_date)
VALUES ('$fn','$ln','$e', SHA1('$p'), NOW() ) " ;
$r = mysqli_query ( $link, $q) ;

 if ( empty ($errors ))

$q = "SELECT user_id FROM users WHERE email='$e'" ;
$r = mysqli_query ( $link , $q ) ;
if ( mysqli_num_rows($r) != 0 )
{ $errors[] = ' Email Address Already Registered. <a href=" ">Log In Here</a> ' ; }
else
{
mysqli_query("INSERT INTO 'users'
(first_name, last_name, email, pass, reg_date)
VALUES ('$fn','$ln','$e', SHA1('$p'), NOW() ) ") ;
}

关于php - 插入MYSQL失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24475205/

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