错误:仅从按钮

时间:2018-11-14 08:05:25

标签: php html

我的问题是,我有3种DB产品。应该有1个产品具有禁用按钮,但是总共3个产品都具有禁用按钮,这是错误的。我回显了“ $ dss2” 的值,发现它只需要我的图片链接中下面显示的1个产品。

$ dss2 根据其产品应该具有不同的价值

我不知道问题所在,因为这些代码在我从数据库循环中获取的内部。这对我有很大帮助。已经为这个错误工作了几天。

这是我的代码,用于从数据循环中获取产品的详细信息:

<?php 
    include('connectdb.php');
    $sql = "SELECT * from posted WHERE (seller='$userid') and (prod='$produkto') and (activityset='GROUP')  and (datee = '$araw')";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {             
    $result = $conn->query($sql); ?>
    <?php while($data = $result->fetch_assoc()) { 
    $dc = $data["dateclick"];
    **$dss2 = $data["datestart"];**
    $equaldate = $data["datee"];
    $as2 = $data["activityset"];
    }} ?>

这是我的按钮代码:

<!-- Group -->
      <?php
      if ($produkto == $row['cartname']) { 
         if ($dss2 > $datetoday) { ?>
        <button type="button" class="btn btn-info btn-sm" title="Return after 1-2 hours" data-toggle="modal" data-target="#modal-4" disabled>Group <?php echo $groupcount ?>/3</button>
      <?php }
        else { ?>
         <button type="button" class="btn btn-info btn-sm" title="Return after 1-2 hours" data-toggle="modal" data-target="#modal-4" disabled>Group <?php echo $dss2 ?><?php echo $groupcount ?>/3</button>
      <?php } } ?>

按钮代码也位于我的提取循环中

1 个答案:

答案 0 :(得分:2)

您需要像这样更正循环+按钮代码:

<?php 
    include('connectdb.php');
    $sql = "SELECT * from posted WHERE (seller='$userid') and (prod='$produkto') and (activityset='GROUP')  and (datee = '$araw')";
    $result = $conn->query($sql);
    if($result->num_rows > 0) {             
        while($data = $result->fetch_assoc()) { 
            if ($produkto == $data['cartname']) { // i don't know from where $produkto is coming so check yourself

                if (strtotime($data["datestart"]) > strtotime($datetoday)) { ?>

                <button type="button" class="btn btn-info btn-sm" title="Return after 1-2 hours" data-toggle="modal" data-target="#modal-4" disabled>Group <?php echo $groupcount ?>/3</button><!-- from where you got $groupcount? you have to check yourself-->

                <?php }else { ?>

                    <button type="button" class="btn btn-info btn-sm" title="Return after 1-2 hours" data-toggle="modal" data-target="#modal-4" disabled>Group <?php echo $dss2 ?><?php echo $groupcount ?>/3</button>

            <?php } 
            }
        }

    }
?>

注意:您的SQL代码容易受到 SQL注入攻击,因此您不应直接将变量注入SQL字符串中。为了防止这种情况,请使用 准备好的语句

参考文献: