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

时间:2017-06-30 05:09:00

标签: php

在Stackoverflow上发布脚本的新手,所以请注意我的上传技巧。我正在登录并在php中注册代码以连接我的数据库。当我运行if else时,什么也没发生。我尝试了error()<?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"'; } } } ?>

    node {
     stage('checkout') {
                git credentialsId: 'Gitlab_cred', url: 'urlhere'
         }

         stage('Build') {
                    docker.image('mvn_custom_image').inside('-u root'){
                      //mvn commands to build the project
                    }
          }

         stage('Archive and Packaging') {
            archiveArtifacts '**/*.war'
          }

         stage('Integration Test') {
            docker.image('selenium/node-firefox:3.4.0-dysprosium').inside{
                 //I want to run mvn command using selenium here
                // This image doesn't have mvn

            }
        }
     }

1 个答案:

答案 0 :(得分:0)

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

变化:

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

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

类似于其他bindParams次来电。可以找到更多帮助here