Neoraven456 Posted July 3, 2008 Share Posted July 3, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/ Share on other sites More sharing options...
.josh Posted July 3, 2008 Share Posted July 3, 2008 no error messages? Very first thing I notice is in your 2nd code block, you forgot a ; after $id = $_POST['id'] Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/#findComment-580643 Share on other sites More sharing options...
bluejay002 Posted July 3, 2008 Share Posted July 3, 2008 dizzy . can you point it clearer? say what error and which script does it point to? my apologise, am lazy reading long posts. Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/#findComment-580649 Share on other sites More sharing options...
Neoraven456 Posted July 3, 2008 Author Share Posted July 3, 2008 no error messages? Very first thing I notice is in your 2nd code block, you forgot a ; after $id = $_POST['id'] Fixed the ;, still no luck =/ no error messages, I'm a PHP noob, how would I go about putting in messages to catch errors? Should be a pretty simple design, I was hoping wouldn't be a need for a lot of troubleshooting xD Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/#findComment-581108 Share on other sites More sharing options...
madk Posted July 3, 2008 Share Posted July 3, 2008 <?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> <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> If I understand what you are looking to accomplish the above code should work. Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/#findComment-581126 Share on other sites More sharing options...
Neoraven456 Posted July 4, 2008 Author Share Posted July 4, 2008 I managed to get everything working this afternoon. As of now I'm unsure what the problem was, I just rebuilt the pages over again, going line by line to find where it failed. I think my syntax $query = "select ... id='$id'"; was off at some point, but it's all fixed now =D Thank you for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/113033-solved-stuck-need-helping-finding-error-in-a-blog-update-script/#findComment-581460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.