I'm creating a blog via PHP/MySQL. I have an add page working, and below I'm going to list three blocks of code that correspond to three pages in an update process. The first block lists all posts ordered by id, once a post is selected it points to the second page/script that should echo the rows into text fields for editing, and a third and final that should update the database and return a confirmation. I'm stuck between and 1 and 2, the list shows up, and when redirected the actual editing page is blank, and I can't seem to find the error.
This is my first post here, so I'm hoping I posted in the right section. Thanks!
Here is the first block that lists the posted blogs:
<?php require ('sql_connect.php4');
sql_connect('nut_blog');
$query = "select * from blog ORDER BY id DESC";
?>
<html>
<head>
</head>
<style type="text/css">
BODY { background: url(http://www.pickellnutrition.com/pics/mainback.jpg); background-repeat: no-repeat; overflow:hidden}
.style1 {font-family: Georgia, "Times New Roman", Times, serif}
</style>
<?php
If ($results = mysql_query ($query)) {
?>
<table align="center" border="1" width="80%">
<tr>
<td colspan="2">
<b><center>
Blog Edit Page
</center></b>
</td>
</tr>
<?php
While ($row = mysql_fetch_array($results)) {
$title = $row['title'];
$author = $row['author'];
$id = $row['id'];
$date = $row['date'];
$entry = $row['entry'];
?>
<tr>
<td colspan="2">
<table align="center" border="0" width="100%">
<tr>
<td>
<b><?php echo $title ?></b> - Posted by: <b><?php echo $author; ?></b>
</td>
<td>
<div align="right"><?php echo $date; ?></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><?php echo $entry; ?></td>
</tr>
<tr>
<td>
<table align="center" width="200" border="0">
<tr>
<td>
<form action="SimpleEdit.php" method="POST">
<input type="hidden" name="id" value="<?= $id ?>">
<input type="submit" name="submit" value="Edit">
</form>
</td>
<td>
<form action="delete.php" method="POST">
<input type="hidden" name="id" value="<?= $id ?>">
<input type="submit" name="submit" value="Delete">
</form>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
</table>
<div align="center">
<p>
<?php
} else {
die ("<p>Could not run query because: <b>" . mysql_error() . "</b></p>\n");
}
mysql_close();
?>
</div>
</html>
Okay, so the first page works well. Does what it's supposed to do. Now the second block that is supposed to bring up all selected post from the first block into editable fields for updating:
<?php require ('sql_connect.php4');
sql_connect('nut_blog');
$id = $_POST['id']
$query = "select * FROM blog WHERE id='$id'";
if ($results = mysql_query($query)) {
$row = mysql_fetch_array ($results){;
$title = $row['title'];
$author = $row['author'];
$id = $row['id'];
$date = $row['date'];
$entry = $row['entry'];
?>
<html>
<head>
</head>
<style type="text/css">
BODY { background: url(http://www.pickellnutrition.com/pics/mainback.jpg); background-repeat: no-repeat; overflow:hidden}
.style1 {font-family: Georgia, "Times New Roman", Times, serif}
</style>
<center>
<form action="SimpleEditSave.php" method="POST">
<table>
<tr>
<td>
Entry Title:
</td>
<td>
<input type="text" name="title" size="40" maxsize="100" value="<?= echo $title ?>" />
</td>
<td>
User:
</td>
<td>
<input type="text" name="title" size="20" maxsize="50" value="<?= echo $user ?>" />
</td>
</tr>
<?php
}
?>
<tr>
<td colspan=2>
<p> </p>
<p>Entry Text:
</p></td>
</tr>
<tr>
<td>
<textarea name="entry" cols="100" rows="15"><?= echo $entry ?></textarea>
</td>
</tr>
<tr>
<td>
<form action="SimpleEditSave.php" method="post">
<input type="hidden" name="id" value="<?php echo $id ; ?>" />
<input type="submit" name="submit" value="Edit" />
</form>
</td>
<td>
<form action="SimpleEditList.php" method="post">
<input type="submit" name="submit" value="Cancel" />
</form>
</td>
</tr>
</center>
</html>
That section doesn't work and so I have yet to be able to test the third section that updates the database but this is what I have:
<?php require ('sql_connect.php4');
sql_connect('nut_blog');
$query = "select * from blog ORDER BY id DESC";
?>
<html>
<head>
</head>
<style type="text/css">
BODY { background: url(http://www.pickellnutrition.com/pics/mainback.jpg); background-repeat: no-repeat; overflow:hidden}
.style1 {font-family: Georgia, "Times New Roman", Times, serif}
</style>
<?php
$title = $_POST['title'];
$entry = $_POST['entry'];
$author = $_POST['author'];
$id = $_POST['id'];
trim ($title);
trim ($entry);
trim ($author);
$title = addslashes ($title);
$entry = addslashes ($entry);
$author = addslashes ($author);
$query = "UPDATE blog SET title='$title', entry='$entry', author='$author' WHERE id='$id'";
$results = mysql_query ($query);
?>
<table>
<?php
if (mysql_affected_rows() == 1) {
?>
<table>
<tr>
<td>
Update Saved Successful
</td>
</tr>
<?php
} else {
?>
<tr>
<td>
Update Failed
</td>
</tr>
<?php
}
?>
<tr>
<td>
<form action="simpleadmin.php" method="post">
<input type="submit" name="submit" value="Ok" />
</form>
</td>
</tr>
</table>
<?php
mysql_close(); //Closes our SQL session
?>
Okay so that's everything. Parts of this were taken from a guide a friend had directed me too, which I am obviously too inept to follow, and parts have been put together from what I do know of PHP. Thanks in advance!