I was following this tutorial on how to modify a sql database. Everything seems fine in that but when i run my code below i get an error saying undefined index in line 11 and 12 are not defined. Can anybody point my mistake? Can i even use variable from one block in another?(the guy in the tutorial does)
<?php
include '/connection.php';
if(!isset($_POST['submit'])){
$query="SELECT * FROM SHOP WHERE ID=$_GET[id]";
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
$shop=mysqli_fetch_array($result);
}
?>
<form action="modify.php" method="POST">
<input name="name" value="<?php echo $shop['name']; ?>"> //error here
<input name="city" value="<?php echo $shop['city']; ?>"> //and here
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<input type="submit" name=submit value="modify">
</form>
<?php
if(isset($_POST['submit'])){
$q1="UPDATE shop SET name='$_POST[name]',city='$_POST[city]' WHERE ID=$_POST[id]";
mysqli_query($conn,$q1)or die(mysqli_error($conn));
}
?>