我的变量已成功显示给用户但我的SQL查询无法看到它

时间:2017-09-13 17:30:51

标签: php html mysql variables

我试图让我的程序获取发布的id并使用它来更新我的数据库中的其他字段,当我回显变量时它工作正常,但是如果我回显我的sql字符串它不在那里

    <body class="container">
  <form class="form-horizontal" method="post"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
      <div class="form-group">
          <label for="amount"><?php echo $id; ?></label>
          <input type="number" name ="amount" class="form-control" id="amount" placeholder="Hvað viltu hækka/lækka um marga kassa?">
      </div>
      <button type="submit" name="plus" class="btn btn-default"><i class="fa fa-plus" aria-hidden="true"></i></button>
      <button type="submit" name="minus" class="btn btn-default"><i class="fa fa-minus" aria-hidden="true"></i></button>
  </form>
</body>

php code

require_once("include/header.php");
require_once("include/mysqliConn.php");
$id = $_POST['number'];
$orginal = $_POST['magn'];
if(isset($_POST['plus'])){
  $amount = $_POST['amount'];
  $finalAmount = $orginal+$amount;
  $sql = 'UPDATE stada SET Magn="'.$finalAmount.'", lastModified="Aron DC" WHERE Nr="'.$id.'"';
  echo $sql;
  if ($conn->query($sql) === TRUE) {
      echo "New record created";
  } else {
      echo "Error: " . $sql . "<br>" . $conn->error;
  }

  $conn->close();
}
if(isset($_POST['minus'])){
  if ($orginal>$amount) {
    $amount = $_POST['amount'];
    $finalAmount = $orginal-$amount;
    $sql = 'UPDATE stada SET Magn="'.$finalAmount.'", lastModified="Aron DC" WHERE Nr="'.$id.'"';

    if ($conn->query($sql) === TRUE) {
        echo "New record created";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
  }else{
    echo '<script>alert("Þú getur ekki tekið fleiri kassa en eru til á lager");</script>';
  }

}

这是一张图片

enter image description here

0 个答案:

没有答案