2017-06-30 5 views
1

Stackoverflowにスクリプトを投稿するのが初めてです。私はデータベースに接続するためにPHPでログインとサインアップのコードを作成しています。 stmt->execute()を実行しているときに何も起こっていません。stmt-> execute();何も与えず、エラーメッセージでもない

変更:

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

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

同様に、他のbindParamsに私はbindParamで3番目のパラメータとしてデータ型を追加する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"'; 
     } 
    } 
} 
?> 
+0

キャッチで$メッセージを確認してください。 – Deep

+0

@Deep申し訳ありませんでした。 –

答えて

0

試してみましたコール。その他のヘルプが見つかりましたhere

関連する問題