I found a great book PHP and MySQL: Novice to Ninja by Kevin Yank. It’s just what I want to know about.
Following the instructions, I have built a jokes database. There are 4 files: index.php, jokes.html.php, form.html.php and error.html.php
The file index.php first shows the content of the db in the browser and allows me to add a joke or delete a joke. It works fine!
I don’t really understand what the ? in the ‘add a joke’ link or in the 'form action=?addjoke does.
Can you please explain it?
index.php first logs me into the db then calls jokes.html.php
while ($row = $result->fetch())
{
$jokes[] = array('id' => $row['id'], 'text' => $row['joketext']);
}
include 'jokes.html.php';
jokes.html.php has this:
<body>
<p><a href="?addjoke">Add your own joke</a></p>
<p>Here are all the jokes in the database jokes:</p>
<p>Each joke is in a form, the submit button is the delete button. If you click delete, the joke will be gone.</p>
<?php foreach ($jokes as $joke): ?>
<form action="?deletejoke" method="post">
<blockquote>
<p>
<?php echo htmlspecialchars($joke['text'], ENT_QUOTES,'UTF-8');
?>
<input type="hidden" name="id" value="<?php echo $joke['id']; ?>">
<input type="submit" value="Delete">
</p>
</blockquote>
</form>
<?php endforeach; ?>
</body>
Both the ‘a href’ and ‘form action=’ have a ?:
`href="?addjoke"`
action="?deletejoke"
index.php also has for example this to add a joke:
if (isset($_GET['addjoke']))
{
include 'form.html.php';
exit();
}