Ich habe die Daten von SQL aufgerufen und durch die ID ausgewählt, dann möchte ich die Daten aus "mysqli_fetch_array" row [1] verwenden, um eine Berechnung durchzuführen.Fehlende variable Daten von SQL
aber irgendwie in Zeile 14 kann die $ row [1] nicht das Datum für die Berechnung bekommen.
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
<?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>
am ehesten, wenn Sie einreichen 'edit.php', ist die ID nicht dort mehr, also die ausgewählte Zeile ist auch nicht da, meine Vermutung ist, dass Sie die gleiche URL in Ihrem Formular beibehalten sollten – Ghost
Ihr Code ist anfällig für SQL Injektionen. Bitte lernen Sie [vorbereitete Aussagen] (https://www.youtube.com/watch?v=nLinqtCfhKY). –