surreal5335 Posted January 28, 2010 Share Posted January 28, 2010 I am trying to create an update to a post function, while the update does occur, the page routing and selecting of posts to be updated is whats getting screwed up. I have so many files involved in this whole mess that I didnt know where to start with what. So I went to the trouble of creating a reference page summing up each file, variable, and included file to trace where elements are going. My website link is: http://royalvillicus.com/post_ads/controller_posts.php/ I have error reporting on as you will notice. things to pay attention to: the url - when clicking on the edit post it will try to access a post id that does not exist saving changes - url will add a "update" to the end of it. This is meant to be a temp page thanking user for updating page then redirect to list of all posts created which is not happening. This occurs in post_update.php The link I sent - it is suppose to hold a list of the posts created. Currently there are two in my database. Only the first one is showing. Here is my reference page: variables: $connection - model_posts.php $id - model_posts.php $_GET - index.php $matches - index.php $msg - controller.php $_POST - index.php $params - controller_posts.php create.php index.php model_posts.php post_create.php post_update.php $post - _form.php _post.php controller_posts.php view_post.php $posts - controller_posts.php view_post.php $query - model_posts.php $result - model_posts.php $route - index.php $routes - index.php $route_match - index.php $_SESSION - layout.php application.php controller_posts.php controller.php $url - index.php $urls - index.php includes: application.php - include_once(VIEW_PATH.'view_posts.php'); config.php - include_once('controller.php'); controller_posts.php - include_once ('config.php'); include_once('model_posts.php'); edit.php - include_once('_form.php'); index.php - include_once('config.php'); include_once(CONTROL_PATH.$route['control'].'.php'); layout.php - include_once(VIEW_PATH.'view_posts.php'); model_posts.php - include_once('config.php'); new.php - include_once('_form.php'); post_create.php - include_once('model_posts.php'); post_update.php - include_once('model_posts.php'); view_posts.php - include_once('_post.php'); files: _form.php - no included files <fieldset> no <form> $post two text fields - title and body _post.php - href="<?php echo APP_ROOT; ?>controller_posts.php/<?php echo $post['id']; ?>" $post: four parameters - title, body, name, email no text fields application.php - <?php echo $_SESSION['flash']['notice']; ?> <?php include_once(VIEW_PATH.'view_posts.php'); ?> <h1>application layout</h1> no text fields html output for posts config.php - url array routes defined constants include_once('controller.php'); controller.php - function redirect_to($address) {} flash_warning($msg) {} flash_notice($msg) {} $_SESSION['flash']['notice'] $address $msg controller_posts.php - error reporting include_once ('config.php'); include_once('model_posts.php'); switch ($route['view']) {} $post = find_post($params['id']); $posts = find_posts(); create_post ($params['post'] $params['post']['id'] = $params['id']; update_post ($params['post'] create.php - <?php print_r($params);?> edit.php - <form action="<?php echo APP_ROOT.$route['control']?>.php/<?php echo $post['id']; ?>/update" include_once('_form.php'); index.php - include_once('config.php'); function dispatcher($routes) {} $url = $_SERVER['REQUEST_URI']; $params = parse_params(); $route_match $routes $route $urls $matches include_once(CONTROL_PATH.$route['control'].'.php'); dispatcher($routes); function parse_params() { $params = array_merge($params, $_POST); $_POST $_GET } layout.php - $_SESSION['flash']['notice'] include_once(VIEW_PATH.'view_posts.php'); model_posts.php - include_once('config.php'); function db_connect () { $connection !mysql_select_db(DATABASE, $connection) } function create_post ($params) { $query = sprintf(); mysql_real_escape_string($params['title']), $result = mysql_query($query); } function update_post ($params) { $query = sprintf(); mysql_real_escape_string($params['title']), $result = mysql_query($query); } function delete_post ($id) { $query = sprintf(); mysql_real_escape_string($id) $result = mysql_query($query); } function find_posts() { $query = $result = mysql_query($query); $number_of_posts = @mysql_num_rows($result); $result = result_to_array($result) or die("SQL failure: "} function find_post($id) { $query = sprintf() $result = mysql_query($query); $number_of_posts = @mysql_num_rows($result); $row = mysql_fetch_array($result);} function result_to_array($result) { $result_array = array(); for ($i=0; $row = @mysql_fetch_array($result); $i++) { $result_array[$i] = $row;}} new.php - action="<?php echo APP_ROOT.$route['control']?>.php/creation" include_once('_form.php'); post_create.php - include_once('model_posts.php'); create_post ($params['post']); <meta http-equiv="refresh" content="5;url=/post_ads/controller_posts.php/"> post_update.php - include_once('model_posts.php'); update_post ($params['post']); <meta http-equiv="refresh" content="5;url=/post_ads/controller_posts.php/"> view_posts.php - $posts $post foreach($posts as $post) { include_once('_post.php');} [<a href=<?php echo APP_ROOT; ?>controller_posts.php/<?php echo $post['id]; ?>/edit">edit post</a>] This may seem like a lot, atleast it does for me, hopefully this summary I created will prove helpful in what to do next. I appreciate the help in the matter Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/ Share on other sites More sharing options...
Adam Posted January 28, 2010 Share Posted January 28, 2010 The reference sheet doesn't really help with finding the issue, except to a provide a little insight. Code you post the relevant code? "_post.php" would be useful.. Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003057 Share on other sites More sharing options...
surreal5335 Posted January 28, 2010 Author Share Posted January 28, 2010 Thanks a lot for the reply, I created it out of frustration of having to open and scan through each different file manually to just remember what variables, functions, and includes are where. _post.php <div class="post"> <a href="<?php echo APP_ROOT; ?>controller_posts.php/<?php echo $post['id']; ?>"> <h2><?php echo $post['title']; ?></h2></a> <span class="body_text"> <?php echo $post['body'].'<br/>'; ?> </span> <span class="name"> <?php echo $post['name'].'<br/>'; ?> </span> <span class="email"> <?php echo $post['email'].'<br/>'; ?> </span> </div> The line I believe to be of trouble is in my index.php if ($url == $route['control'].'.php/'.$post['id'].'/edit') { include_once(VIEW_PATH.'edit.php'); } else if ($url == $route['control'].'.php/'.$post['id'].'/update') { include_once(VIEW_PATH.'post_update.php'); } mainly the $post['id'] I really have no idea why its having troubles, but this is the line that doing the routing to pages and displaying posts depending on the id selected by the user. Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003171 Share on other sites More sharing options...
Adam Posted January 28, 2010 Share Posted January 28, 2010 Do you mean "$_POST", or actually "$post"? Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003175 Share on other sites More sharing options...
surreal5335 Posted January 28, 2010 Author Share Posted January 28, 2010 ya its actually $post Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003224 Share on other sites More sharing options...
Adam Posted January 28, 2010 Share Posted January 28, 2010 Okay. Where in "_post.php" is $post declared, or where is it originally declared if "_post.php" is included? Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003249 Share on other sites More sharing options...
surreal5335 Posted January 29, 2010 Author Share Posted January 29, 2010 well I would say it was originally declared in controller_posts.php for the mere fact it was one of first files I created. Here is the switch statment that holds the $post variable in it. switch ($route['view']) { case "show": $post = find_post($params['id']); break; case "index": $posts = find_posts(); break; case "edit": $post = find_post($params['id']); break; case "new": break; case "create": if(create_post ($params['post'])) { //$_SESSION['flash']['notice'] = 'Successfully created post!'; //flash_notice('Successfully created post!'); //redirect_to('controller_posts.php/'); } break; case "update": $params['post']['id'] = $params['id']; if(update_post ($params['post'])) { //$_SESSION['flash']['notice'] = 'Successfully created post!'; //flash_notice('Successfully updated post!'); //redirect_to('post_update.php'); } break; } I took a look around and noticed that controller_posts.php has not been included in index.php or _post.php. This may not have been a problem until now bc I have moslty using controller_posts.php for my main page. Would this be a correct assumption? Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003416 Share on other sites More sharing options...
Adam Posted January 29, 2010 Share Posted January 29, 2010 Okay, how is that linked to "_post.php"? Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003421 Share on other sites More sharing options...
surreal5335 Posted January 29, 2010 Author Share Posted January 29, 2010 I just included controller_posts.php into index.php and _post.php and I am still getting the same result. Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1003428 Share on other sites More sharing options...
surreal5335 Posted January 30, 2010 Author Share Posted January 30, 2010 would it matter that the defined $post variable is inside a switch? Quote Link to comment https://forums.phpfreaks.com/topic/190079-update-post-issues/#findComment-1004125 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.