dqjl0906 2017-02-05 22:52
浏览 30
已采纳

PHP-为什么我的数据被插入mySQL表两次?

When I run the php file below it inserts data into mysql table twice. I don't run the insert command again anywhere, both entries have unique ids. Any ideas why?

Dumb of me Here it is:

<?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();
?>
  • 写回答

1条回答 默认 最新

  • dongyi1015 2017-02-05 23:13
    关注

    In the if statement it is inserting the row again.

    Solutions:

    (1)Remove if statement. Issue:Won't check for error now.

    (2)Place die(); after

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

    Issue:Won't check for error now.

    (3) Best option: Remove line

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

    If statement will query and check for error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据