query
Can you please help with the memers.json file. ?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CRUD Operation on JSON File using PHP</title> </head> <body> <a href="add.php">Add</a> <table border="1"> <thead> <th>ID</th> <th>Firstname</th> <th>Lastname</th> <th>Address</th> <th>Gender</th> <th>Action</th> </thead> <tbody> <?php //fetch data from json //decode into php array $index = 0; foreach($data as $row){ echo " <tr> <td>".$row->id."</td> <td>".$row->firstname."</td> <td>".$row->lastname."</td> <td>".$row->address."</td> <td>".$row->gender."</td> <td> <a href='edit.php?index=".$index."'>Edit</a> <a href='delete.php?index=".$index."'>Delete</a> </td> </tr> "; $index++; } ?> </tbody> </table> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CRUD Operation on JSON File using PHP</title> </head> <body> <form method="POST"> <a href="index.php">Back</a> <p> <label for="id">ID</label> <input type="text" id="id" name="id"> </p> <p> <label for="firstname">Firstname</label> <input type="text" id="firstname" name="firstname"> </p> <p> <label for="lastname">Lastname</label> <input type="text" id="lastname" name="lastname"> </p> <p> <label for="address">Address</label> <input type="text" id="address" name="address"> </p> <p> <label for="gender">Gender</label> <input type="text" id="gender" name="gender"> </p> <input type="submit" name="save" value="Save"> </form> <?php //open the json file //data in out POST 'id' => $_POST['id'], 'firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'address' => $_POST['address'], 'gender' => $_POST['gender'] ); //append the input to our array $data[] = $input; //encode back to json } ?> </body> </html>
<?php //get the index from URL $index = $_GET['index']; //get json data //assign the data to selected index $row = $data_array[$index]; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CRUD Operation on JSON File using PHP</title> </head> <body> <form method="POST"> <a href="index.php">Back</a> <p> <label for="id">ID</label> <input type="text" id="id" name="id" value="<?php echo $row->id; ?>"> </p> <p> <label for="firstname">Firstname</label> <input type="text" id="firstname" name="firstname" value="<?php echo $row->firstname; ?>"> </p> <p> <label for="lastname">Lastname</label> <input type="text" id="lastname" name="lastname" value="<?php echo $row->lastname; ?>"> </p> <p> <label for="address">Address</label> <input type="text" id="address" name="address" value="<?php echo $row->address; ?>"> </p> <p> <label for="gender">Gender</label> <input type="text" id="gender" name="gender" value="<?php echo $row->gender; ?>"> </p> <input type="submit" name="save" value="Save"> </form> <?php //set the updated values 'id' => $_POST['id'], 'firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'address' => $_POST['address'], 'gender' => $_POST['gender'] ); //update the selected index $data_array[$index] = $input; //encode back to json } ?> </body> </html>
<?php //get the index $index = $_GET['index']; //fetch data from json //delete the row with the index //encode back to json ?>