简体   繁体   English

SQL缺少变量数据

[英]Missing variable data from SQL

I have called the data from SQL and selected by id then i would like to use the data from "mysqli_fetch_array" row[1] to do some calculation. 我从SQL调用了数据,并按ID选择了数据,然后我想使用“ mysqli_fetch_array”第[1]行中的数据进行一些计算。

but somehow at line 14 the $row[1] can't get the date to do calculation. 但是以某种方式在第14行,$ row [1]无法获得进行计算的日期。

index.php 的index.php

<?php
$con = mysqli_connect('localhost','root','','test2');
$query = mysqli_query($con,"SELECT * FROM count") or 
die(mysqli_error($con));


while( $row = mysqli_fetch_array($query))
  echo "$row[id]. $row[quantity] <a href='edit.php?edit=$row[id]'>Draw 
Patrs<br />";
?>

edit.php edit.php

<?php

if( isset($_GET['edit']) )
{
    $id = $_GET['edit'];
    $con = mysqli_connect('localhost','root','','test2');
    $query = mysqli_query($con,"SELECT * FROM count WHERE id='$id'");
    $row = mysqli_fetch_array($query);
}   

if( isset($_POST['drawquantity']) )
{
    $drawquantity = $_POST['drawquantity'];
    $newquantity = $row[1]-$drawquantity;
    $id      = $_POST['id'];
    $sql     = "UPDATE count SET quantity='$newquantity' WHERE id='$id'";
    $con = mysqli_connect('localhost','root','','test2');
    $res     = mysqli_query($con,$sql) 
                                or die("Could not update".mysql_error());
    echo "<meta http-equiv='refresh' content='0;url=index.php'>";

}

?>
<form action="edit.php" method="POST">
How mant you will take away: <input type="text" name="drawquantity" value="" 
placeholder="<?php echo $row[1]; ?>"><br />

<input type="hidden" name="id" value="<?php echo $row[0]; ?>">
<input type="submit" value=" Update "/>
</form>
<?php

if( isset($_GET['edit']) )
{
    $id = $_GET['edit'];
    $con = mysqli_connect('localhost','root','','test2');
    $query = mysqli_query($con,"SELECT * FROM count WHERE id='$id'");
    $row = mysqli_fetch_array($query);
}   

if( isset($_POST['drawquantity']) )
{
    $drawquantity = $_POST['drawquantity'];
    $newquantity = $row[1]-$drawquantity;
    $id      = $_POST['id'];
    $sql     = "UPDATE count SET quantity='$newquantity' WHERE id='$id'";
    $con = mysqli_connect('localhost','root','','test2');
    $res     = mysqli_query($con,$sql) 
                            or die("Could not update".mysql_error());
    echo "<meta http-equiv='refresh' content='0;url=index.php'>";

}

?>
<form action="edit.php?edit=<?=$_GET['edit']?>" method="POST">
How mant you will take away: <input type="text" name="drawquantity" value="" 
placeholder="<?php echo $row[1]; ?>"><br />

<input type="hidden" name="id" value="<?php echo $row[0]; ?>">
<input type="submit" value=" Update "/>
</form>

Change is in action 变革在行动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM