Lodius2000 Posted June 6, 2008 Share Posted June 6, 2008 my blog cms is coming along nicely, but my edit page needs help, on the page where you view a list of rows in the database, i have this code to display some of the row's fields and link each row to the edit page so that the row's content can be altered <?php foreach ($list as $row) { print '<tr><td>' . $row[article_id] .'</td><td><a href="../editform/index.php?id=' . $row[article_id] .'">' . $row[article_title] . '</td><td>' . $row[timestamp] . '</td></tr>'; print "\n"; } ?> this works perfectly in the url, for article_id=1 the web address reads /editform/index.php?id=1 but what I want is for the text and textarea on the edit page to be filled out with the contents of the correct row here is my edit page code <?php //this page edits articles session_start(); require ('../../../install/PEAR/DB.php'); require ('../../../../dbfiles/db_login.php'); $db->setErrorHandling(PEAR_ERROR_DIE); $db->setFetchMode(DB_FETCHMODE_ASSOC); //print a text box function input_text($element_name, $values){ print '<input type="text" name="' . $element_name .'" value="'; print htmlentities($values[$element_name]) . '"/>'; } //print a textarea function input_textarea($element_name, $values){ print '<textarea cols="75" rows="50" name="' . $element_name .'">'; print htmlentities($values[$element_name]) . '</textarea>'; } //grabs article_id for later query $id = $_GET['id']; if ($_SESSION['username']){ if($_POST['_submit_check']){ if($form_errors = validate_form()){ show_form($form_errors); } else { process_form(); } } else { show_form(); } } else { print '<a href="../index.php">Log In dummy</a>'; } function show_form($errors = '') { global $db, $id; $items = $db->getRow('SELECT article_title, article FROM text_cms WHERE article_id = ?', array($id)); $items['article_title'] = $title; $items['article'] = $article; //If form has been submitted, get defaults from submitted variables if ($_POST['_submit_check']){ $defaults = $_POST; } else { $defaults = array('title' => $title, 'body' => $article); } if ($errors){ print 'Please correct these errors: <ul><li>'; print implode('</li><li>', $errors); print '</li></ul>'; } print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; //begin the unique form print '<br />'; print "Article Title"; print "<br />\n"; input_text('title', $_POST); print "<br /><br />\n"; print 'Article Body'; print "<br />\n"; input_textarea('body', $_POST); print "<br /><br /><br />\n"; input_submit('submit', 'Edit Article'); print '<input type="hidden" name="_submit_check" value="1" />'; print "\n"; print '</form>'; } function validate_form(){ if (trim(strlen($_POST['title'])) > 255){ $errors[] = 'Article title is too long, please shorten it'; } return $errors; } function process_form(){ global $db, $id, $title, $article; $edited_title = $_POST['title']; $edited_article = $_POST['body']; //check to see if title has changed, if changed, update db if ($edited_title != $title){ $db->query('UPDATE text_cms SET article_title = $edited_title WHERE article_id = $id'); print "Updated <strong>$title</strong> in the database.<br />\n"; } //check to see if article has changed, if changed, update db if ($edited_article != $article){ $db->query('UPDATE text_cms SET article = $edited_article WHERE article_id = $id'); print "Updated <strong>article body</strong> in the database.<br />\n"; } print '<a href="../managearticle/index.php">Go back to article management</a>'; } ?> this prints the page right but the fields are empty I know almost nothing about $_GET please let me know what I did wrong Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/ Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 check your $_POST var ie: $_POST['body'] b/c I ran function input_text and it gives me correct results Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-559559 Share on other sites More sharing options...
Lodius2000 Posted June 7, 2008 Author Share Posted June 7, 2008 uhhh what? Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-559583 Share on other sites More sharing options...
Lodius2000 Posted June 7, 2008 Author Share Posted June 7, 2008 UPDATE: i have made sure that the variable's $title and $article are not empty by echoing them so I guess my question is what is wrong with my script (Above) that they wont become defaults, so that I can edit them thankyou Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-559650 Share on other sites More sharing options...
sasa Posted June 7, 2008 Share Posted June 7, 2008 in function show_form change part print '<br />'; print "Article Title"; print "<br />\n"; input_text('title', $_POST); print "<br /><br />\n"; print 'Article Body'; print "<br />\n"; input_textarea('body', $_POST); print "<br /><br /><br />\n"; to print '<br />'; print "Article Title"; print "<br />\n"; input_text('title', $default); print "<br /><br />\n"; print 'Article Body'; print "<br />\n"; input_textarea('body', $default); print "<br /><br /><br />\n"; Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-559660 Share on other sites More sharing options...
Lodius2000 Posted June 8, 2008 Author Share Posted June 8, 2008 sasa that didnt work, changed it to $defaults though not $default Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-560758 Share on other sites More sharing options...
keeB Posted June 8, 2008 Share Posted June 8, 2008 Your cms stores page content in a database? Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-560761 Share on other sites More sharing options...
Lodius2000 Posted June 8, 2008 Author Share Posted June 8, 2008 Your cms stores page content in a database? correct Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-560784 Share on other sites More sharing options...
keeB Posted June 8, 2008 Share Posted June 8, 2008 update //grabs article_id for later query $id = $_GET['id']; to //grabs article_id for later query $id = $_GET['id']; die($id); Should have a blank page with the ID. Does it? Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-560785 Share on other sites More sharing options...
Lodius2000 Posted June 9, 2008 Author Share Posted June 9, 2008 it does contain the correct ID, also i have checked the other variables, $title and $article, but they wont show up in the form, i can print them print $title; but when i try to make them the default for the form field they dont show up Quote Link to comment https://forums.phpfreaks.com/topic/109067-solved-creating-an-edit-page-_get-question/#findComment-560786 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.