donglue1886 2019-03-13 07:52
浏览 58
已采纳

函数php中的if / else语句没有插入[关闭]

what i want to do is that it checks the input field and after that it will insert the following query or it it gives an error message. My problem is that my query won't insert.

My PHP function that won't work (other file then html file):

function Code($userID) {
require '../conn.php';
    $sql = "SELECT `current_uses` FROM `sub_codes` WHERE `content` = '".$_POST['Code']."'";
    $result = mysqli_query($conn, $sql);
    $row = mysqli_fetch_array($result);
    if ($row['current_uses'] > 0){
        $query = "INSERT INTO `partner_subscriptions` (`id`, `user_id`, `sub_id`, `allowed_users`, `start_date`, `end_date`) VALUES (NULL, ?, ?, ?, ?, ?);";
        $stmt = $conn->prepare($query);
        $_userID = $userID;
        $_subID = '99'; 
        $_allowedUsers = '100';
        $_startDate = date('Y-m-d');
        $sql2 = "SELECT `end_date` FROM `sub_codes` WHERE `content` = '".$_POST['Code']."'";
        $result2 = mysqli_query($conn, $sql2);
        $row2 = mysqli_fetch_array($result2);
        $_endDate = $row2['end_date'];
        $stmt->bind_param("sssiiii", $_userID, $_subID, $_allowedUsers, $_startDate, $_endDate);
        $stmt->execute();
        $lastID = $conn->insert_id;
        $stmt->close();
        return $lastID;
    }else {
        echo "Wrong code";
    }
}

My html file:

<br/><div class="form-group">
  <label title="Required">Free description code:</label>
   <input type="text" name="Code" class="form-control" id="Code"/>
</div><br/>

The rest of my PHP file (that i think you need to know):

if (usedmail($_POST['username'])==true) {
$lastID = saveUser($_POST['fnln'], $_POST['username'], password_hash($_POST['password'], PASSWORD_BCRYPT), 0, 0, 1);
$niv = NULL;
if ($_POST['type'] == "3") { // If the partner is an educational institution look for niveau
    $niv = NivID($_POST['niv']);
}

Code($lastID, $_POST['Code']);
$path = saveImage();
Contact($lastID);
Image($lastID);
Social($lastID);
Story($lastID);
Skill($lastID);
$orgID = saveOrganisation($lastID, $_POST['organisation'], $path, $_POST['type'], $_POST['branche'], $niv);
updateUser($orgID, $lastID);
}
else {
 header('Location: ../../mailerror');
}

every other function works normal except the code function and i don't really know why. I appreciate your help!

  • 写回答

2条回答 默认 最新

  • dsxon40042 2019-03-13 08:49
    关注

    I had to change "sssiiii" to "iiiss" because Every single character of your 'sssiiii' stands for a single value that is bound to the statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog