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条)

报告相同问题?