php:多个预准备语句不会执行

时间:2017-03-25 20:41:03

标签: php mysql prepared-statement

我有一个PHP脚本可以做几件事。

  1. 确定用户是否已登录。
  2. 如果不是,请列出一些电话号码
  3. 如果是,请列出一些电话号码并增加用户的版本
  4. 回显JSON编码列表
  5. 我正在使用准备好的陈述。一切都很好,直到我尝试增加用户的版本。当我添加这个语句时,什么都不会回显,甚至不是列表。如果我删除更新代码,列表将回显。问题只发生在POST期间。

    评论如下:

    <?php
    include('connections/conn.php');
    
    $userZip = $_GET['zip'];
    
    $uGoogleSecret = $_POST['secret'];
    
    $testsql = $conn->prepare('SELECT * FROM pffusers where uGoogleSecret = ?');
    $testsql->bind_param("i",$uGoogleSecret);
    $testsql->execute();
    $testsql->store_result();
    
    $rarray = array();
    if($testsql->num_rows==0){
        $zipSql = $conn->prepare('SELECT * FROM qryzipsphones where zCode = ? and pActive=1;');
        $zipSql->bind_param("s",$userZip);
        $zipSql->execute();
        $zipSql->store_result();
        if($zipSql->num_rows==0){
            $finalZipSql = $conn->prepare('SELECT * FROM qryzipsphones where zCode = 17103 and pActive=1;');
        } else{
            $finalZipSql = $zipSql;
        }
    } else{
        $zipSql = $conn->prepare('SELECT * FROM qryzipsphones where zCode = ? and pActive=1;');
        $zipSql->bind_param("s",$userZip);
        $zipSql->execute();
        $zipSql->store_result();
        if($zipSql->num_rows==0){
            $finalZipSql = $conn->prepare('SELECT * FROM qryzipsphones where zCode = 17103 and pActive=1;');
        } else{
            $finalZipSql = $zipSql;
        }
    }
    
    $finalZipSql->execute();
    $res = $finalZipSql->get_result();
    while($finalZip=$res->fetch_assoc()){
        array_push($rarray,array(
        'pid'=>$finalZip['pid'],
        'pName'=>$finalZip['pName'],
        'pDisplayNumber'=>$finalZip['pDisplayNumber'],
        'pNumber'=>$finalZip['pNumber'],
        ));
    }
    
    $finalZipSql->close();
    
    //Problem begins here
    $usql = $conn->prepare('SELECT * FROM pffusers where uGoogleSecret = ?');
    $usql->bind_param("i",$uGoogleSecret);
    $usql->execute();
    $usql->store_result(); 
     if($usql->num_rows==1){
        $urow = $usql->fetch_assoc();
        $uid = $urow['uid'];
        $uversion = $urow['uVersion'];
        $uversion++;
        $uUser = $conn->prepare('update pffusers set uVersion=? where uid=?;');
        $uUser->bind_param("ii",$uversion,$uid);
        $uUser->execute();
    }
    //Problem ends here
    
    echo json_encode(array('result'=>$rarray));
    ?>
    

0 个答案:

没有答案