PHP MySQL novice to ninja 6th edition – edit function (p.377)

Hello. The text which to edit doesn’t appear in the form input window. As was found $_GET with id of the edited joke doesn’t appear in the index.html file after clicking on the link (in file: jokes.html.php):

<a href="/joke/edit?id=<?=$joke['id']?>">Edit</a>

Have someone found a decision?

Can you post some more of the code, we don’t all have a copy of the book. Specifically, the code that populates the $joke array, and the code you use in edit to retrieve the id.

Of course.
The code that populates the $joke array (jokes.html.php):

<a href="/joke/edit?id=<?=$joke['id']?>">Edit</a>

the code you use in edit to retrieve the id (JokeController.php):

public function edit() {
		var_dump($_GET);    //return: array (size=0)  empty
		if (isset($_POST['joke'])) {
			$joke = $_POST['joke'];
			$joke['jokedate'] = new DateTime();
			$joke['authorId'] = 1;
			header('location: /joke/list');
		else {
			if (isset($_GET['id'])) {
				$joke = $this->jokesTable->findById($_GET['id']);
			$title = 'Edit joke';

			return ['template' => 'editjoke.html.php',
					'title' => $title,
					'variables' => [
						'joke' => $joke ?? null

$joke will be defined in either valid case (either you’ve posted a joke, at which point you’re saving an edit, or you’ve clicked on something that has taken you to the joke editing page, at which point there should be an ID in the query string.)

However, the jokes.html.php you’ve copied that line out of doesn’t appear to match the GitHub repository version. The version you’re showing has an array indexer, and the github version has a property accessor.

Now, there’s a chance i’m looking at the wrong branch of the repo here, but unless @TomB changed his formatting styles between branches… are you SURE you’ve got the correct version of the code samples?

I tried this [GitHub repository version] ( . which you gave me.

Changed code in jokes.html.php:

<a href="/joke/edit?id=<?=$joke['id']?>">Edit</a> 


<a href="/joke/edit?id=<?=$joke->id?>">Edit</a>

Off Topic:

@andreichornii: when you post code on the forums, you need to format it so it will display correctly. (I’ve edited your post above for you.)

You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.

but after that it doesn’t passes jokes id in the DOM where list of jokes.
Example of link “Edit”:

<a href="/joke/edit?id=13">Edit</a>


<a href="/joke/edit?id=">Edit</a>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.