2017-02-05 14 views
-2

以下のphpファイルを実行すると、mysqlテーブルにデータが2回挿入されます。どこでもinsertコマンドを実行しません。両方のエントリにユニークなIDがあります。なぜどんなアイデア?私のダムPHP - データがmySQLテーブルに2回挿入されるのはなぜですか?

ここにある:if文で

<?php 
require "conn.php"; 
require "stripe-php-4.4.0/init.php"; 
$fname = $_POST['fname']; 
$lname = $_POST['lname']; 
$email = $_POST['email']; 
$phonenum = $_POST['phonenum']; 
$pin = $_POST['pin']; 
$device = $_POST['device']; 
$timeout = $_POST['timeout']; 
$token = $_POST['stripeToken']; 


// Set your secret key: remember to change this to your live secret key in production 
// See your keys here: https://dashboard.stripe.com/account/apikeys 
\Stripe\Stripe::setApiKey("secretkey"); 

// Create a Customer: 
$customer = \Stripe\Customer::create(array(
    "email" => $email, 
    "source" => $token, 
)); 

// Save the customer ID and other info in a database for later. 
$newCustID = $customer->id; 
$insert_new_user = "INSERT INTO zeus_borrowers (fname,lname,email,phonenum,pin,stripecusid,timeout,device) VALUES ('$fname','$lname','$email','$phonenum','$pin','$newCustID','$timeout','$device')"; 
$result = mysqli_query($conn ,$insert_new_user); 

if($conn->query($insert_new_user) === TRUE){ 
} 
else{ 
    echo "Error: " . $insert_new_user . "<br>" . $conn->error; 
} 
$conn->close(); 
?> 
+0

コードが表示されません。 –

+1

ええ;ゴブリン... 2人。 –

+0

助けを借りてくれてありがとう! – aheit

答えて

0

それが再び行を挿入しています。

解決策:

(1)if文を削除します。問題:今エラーをチェックしません。

(2)die();後:

$result = mysqli_query($conn ,$insert_new_user); 

問題:今すぐエラーを確認しません。

(3)ベストオプション:文が照会して、エラーをチェックする場合はライン

$result = mysqli_query($conn ,$insert_new_user); 

を削除します。

+1

あるいは、if($ conn-> query($ insert_new_user) 'を' if($ result) 'に置き換えてください。 –

関連する問題