@spaceshiptrooper, thanks the book does suggest xampp for windows.
I do now believe my code is at fault, localhost is now showing my
code and what has happened is this… the sample website the book
builds is putting jokes into the database. I am putting a delete
button on each joke. It does this but it is adding a button on
every line indefinitely! So I add the code for checking and
I thank you for your time.
@John_Betong I will be glad to try this thank you, i will put the
code up first to see if that changes anything.
@Gandalf thanks, skype is installed on my laptop but i don’t use
it. I can’t see that it would suddenly change anything, and I now
believe my code to be at fault.
index.php
<?php
if (get_magic_quotes_gpc())
{
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process))
{
foreach ($val as $k => $v)
{
unset($process[$key][$k]);
if (is_array($v))
{
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
}
else
{
$process[$key][$stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}#--------------------------------------magic quotes---------------------------------------------------
if (isset($_GET['addjoke']))
{
include 'form.html.php';
exit();
}#--------------------------------------form-----------------------------------------------------------
try {
$pdo = new PDO('mysql:host=localhost;dbname=ijdb', 'ijdbuser', 'mypassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$error = 'Unable to connect to the database server.';
include 'error.html.php';
exit();
}
#--$output = 'Database connection established.';
#--include 'output.html.php';
#--------------------------------------------connection----------------------------------------------------
if (isset($_POST['joketext']))
{
try {
$sql = 'INSERT INTO joke SET
joketext = :joketext,
jokedate = CURDATE()';
$s = $pdo->prepare($sql);
$s->bindValue(':joketext', $_POST['joketext']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error adding submitted joke: ' . $e->getMessage();
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}#---------------------------------------add joke to database------------------------------------------
if (isset($_GET['deletejoke']))
{
try {
$sql = 'DELETE FROM joke WHERE id = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_POST['id']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error deleting joke: ' . $e->getMessage();
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}#--------------------------------------delete joke----------------------------------------------------
#--------------------------------------display jokes--------------------------------------------------
while ($row = $result->fetch())
{
$jokes[] array('id' => $row['id'], 'text' => $row['joketext']);
}#-----------------------------------store jokes---------------------------------------------------
include 'jokes.html.php';
jokes.html.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>List of Jokes</title>
</head>
<body>
<p><a href="?addjoke">Add your own joke</a></p><br>
<p>Here are all the jokes in the database:</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>
</html>
form.html.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Add Joke</title>
<style type="text/css">
textarea {
display: block;
width: 100%;
}
</style>
</head>
<body>
<form action="?" method="post">
<div>
<label for="joketext">Type your joke here</label>
<textarea id="joketext" name="joketext" rows="3" cols="40"></textarea>
</div>
</form>
<div><input type="submit" value="Add Joke"></div>
</body>
</html>
error.html.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Script Error</title>
</head>
<body>
<p>
<?php echo $error; ?>
</p>
</body>
</html>
Thank you all