stmt->执行();什么也没给,甚至没有错误信息

克鲁什纳声纳

在 Stackoverflow 上发布脚本的新手,所以请注意我的上传技巧。我正在登录并在 php 中注册代码以连接我的数据库。当我运行时stmt->execute(),什么也没有发生。我想if elseerror()

<?php
// begin our session 
session_start();


//first check that both the username, password and form token have been sent 
if(!isset( $_POST['username'], $_POST['password'], $_POST['mailid'], $_POST['firstname'], $_POST['lastname'], $_POST['form_token']))
{
    $message = 'Username and password not valid';
}
// check the form token is valid 

elseif( $_POST['form_token'] != $_SESSION['form_token'])
{
    $message = 'Invalid form submission';
}
elseif (strlen( $_POST['username']) > 20 || strlen($_POST['username']) < 4)
{
    $message = 'Incorrect Length for Username';
}
// check the password is the correct length 
elseif (strlen( $_POST['password']) > 20 || strlen($_POST['password']) < 4)
{
    $message = 'Incorrect Length for Password';
}
// check the username has only alpha numeric characters 
elseif (ctype_alnum($_POST['username']) != true)
{
    // if there is no match ***/
    $message = "Username must be alpha numeric";
}
// check the password has only alpha numeric characters 
elseif (ctype_alnum($_POST['password']) != true)
{
        // if there is no match 
        $message = "Password must be alpha numeric";
}

else
{
    // if we are here the data is valid and we can insert it into database 
    $phpro_username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
    $phpro_password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
    $phpro_mailid = filter_var($_POST['mailid'], FILTER_SANITIZE_STRING);
    $phpro_firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
    $phpro_lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
    // now we can encrypt the password 

    $phpro_password = sha1( $phpro_password );

    // connect to database 
    // mysql hostname 
    $mysql_hostname = 'localhost';

    // mysql username 
    $mysql_username = 'root';

    // mysql password 
    $mysql_password = '';

    // database name 
    $mysql_dbname = 'login';


    try
    {
      $dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
        // $message = a message saying we have connected 

        // set the error mode to excptions 
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        // prepare the insert 
        $stmt = $dbh->prepare("INSERT INTO userdetails (username, mailid, password, firstname, lastname ) VALUES (:phpro_username, :phpro_mailid, :phpro_password, :phpro_firstname, :phpro_lastname)");
        //$stmt = $dbh->prepare("select * from userdetail");

        // bind the parameters 
        $stmt->bindParam(':phpro_username' , $phpro_username );
        $stmt->bindParam(':phpro_password' , $phpro_password );
        $stmt->bindParam(':phpro_mailid'   , $phpro_mailid   );
        $stmt->bindParam(':phpro_firstname', $phpro_firstname);
        $stmt->bindParam(':phpro_lastname' , $phpro_lastname );

        echo "Before execution";
        // execute the prepared statement 
        $stmt->execute();

        //echo "After execution";
        // unset the form token session variable 
        unset( $_SESSION['form_token'] );

        // if all is done, say thanks 
        $message = 'New user added';
    }

         catch(Exception $e)
    {
        // check if the username already exists 
        if( $e->getCode() == 23000)
        {
            $message = 'Username already exists';
        }
        else
        {
            // if we are here, something has gone wrong with the database 
            $message = 'We are unable to process your request. Please try again later"';
        }
    }   
}
?>
迪利普·库马尔

尝试添加数据类型作为第三个参数bindParam

改变:

$stmt->bindParam(':phpro_username' , $phpro_username );

$stmt->bindParam(':phpro_username' , $phpro_username, PDO::PARAM_STR);

其他bindParams调用同理可以在此处找到更多帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

PHP stmt prepare失败,但是没有错误

Mongoose 查询没有正确执行,没有错误信息

Laravel HttpException-没有错误信息

PHP中没有错误信息

什么是G_STMT_START和G_STMT_END?

PHP中的$ stmt是什么

没有错误信息,所以我不知道出了什么问题

带有插入stmt的Oracle游标并发

pgadmin 4,导入csv,错误代码1,没有错误信息

biostring()没有错误信息,但实际上做到了

如果不起作用,请让函数进入内部。(没有错误信息)

Windows 8升级失败-没有错误信息

VirtualBox-无法打开虚拟机的会话。没有错误信息

闪亮的应用程序问题;空白输出;没有错误信息

是什么mysqli_stmt_get_result和mysqli_stmt_store_result之间的区别?

$ stmt-> fetchAll(PDO :: FETCH_ASSOC); 没有结果

我无法使用 C# 更新 Ms Access 中的表。没有错误信息

java.lang.NullPointerException (没有错误信息) 尝试制作签名 apk 时

我的 Flutter 项目没有运行(错误信息)

没有来自curl的错误信息

会话没有开始?+奇怪的错误信息

为什么我在 $v=false 时没有从 perl 得到错误信息?

mysqli_stmt_execute()不执行准备好的查询

PHP在stmt准备并执行语句后获取结果

未定义的函数mysqli_stmt_init()php错误

MySQL的出勤报告在准备stmt上创建语法错误

mysqli_stmt_bind_result()的参数计数错误

stmt-> execute()(数组到字符串的转换错误)

修复mysql错误mysqli_stmt_bind_param()