I'm trying to create a CRUD system in PHP linked with XML that contains all the info that I want to create a CRUD system with. I'm stuck with editing the basic infos because in this code:
<?php
$movies = simplexml_load_file('sadfg.xml');
if(isset($_POST['submitSave'])) {
foreach($movies->movie as $movie){
if($movie['id']==$_POST['id']){
$movie->movie_code = $_POST['movie_code'];
$movie->title = $_POST['title'];
$movie->directors = $_POST['directors'];
$movie->genre = $_POST['genre'];
$movie->date_of_release = $_POST['date_of_release'];
break;
}
}
file_put_contents('sadfg.xml', $movies->asXML());
header('location:index.php');
}
foreach($movies->movie as $movie){
if($movie['id']==$_GET['id']){
$id = $movie['id'];
$movie_code = $movie->movie_code;
$title = $movie->title;
$directors = $movie->directors;
$genre = $movie->genre;
$date_of_release = $movie->date_of_release;
break;
return;
}
}
?>
if($movie['id']==$_GET['id']) -> this line says unidentified array key
This is my XML file:
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="style.css"?>
<movies>
<movie id="m1">
<movie_code>MOV 1089</movie_code>
<title>Guardians of the Galaxy</title>
<directors>James Gunn</directors>
<genre>Superhero fiction, Sci-Fi, Action</genre>
<date_of_release>July 31, 2014</date_of_release>
</movie>
<movie id="m2">
<movie_code>MOV 1145</movie_code>
<title>Captain America: Civil War</title>
<directors>Anthony Russo, Joe Russo</directors>
<genre>Superhero fiction, Sci-Fi, Action</genre>
<date_of_release>April 27, 2016</date_of_release>
</movie>
<movie id="m3">
<movie_code>MOV 1220</movie_code>
<title>Black Panther</title>
<directors>Ryan Coogler</directors>
<genre>Superhero fiction, Sci-Fi, Action</genre>
<date_of_release>February 16, 2018</date_of_release>
</movie>
<movie id="m4">
<movie_code>MOV 1265</movie_code>
<title>The Avengers: Infinity War</title>
<directors>Anthony Russo, Joe Russo</directors>
<genre>Superhero fiction, Sci-Fi, Action</genre>
<date_of_release>April 25, 2018</date_of_release>
</movie>
<movie id="m5">
<movie_code>MOV 1331</movie_code>
<title>Thor: Ragnarok</title>
<directors>Taika Waititi</directors>
<genre>Superhero fiction, Sci-Fi, Action</genre>
<date_of_release>October 25, 2017</date_of_release>
</movie>
</movies>
Stuck here for a while now, I wonder why this line says that. I can't seem to find the error causing it. Appreciate your thoughts or opinions guys thanks!