jpopuk Posted February 26, 2010 Share Posted February 26, 2010 Hi, I am setting up a mini forum. When the user names a detailed post, I want them to be able to EDIT the post, when they click edit post page I am using: <?php echo $post['message']; ?> this code brings up the message they submitted in their original post so they can edit it. I am having trouble with trying to do the same for the other fields, ad_type, pet_type, breed, gender, colours, dob, available and price. Here is the code for the edit post page: if (isset($_GET['action']) && $_GET['action'] == 'edit_post') { if ($post['user_id'] != $user_data['user_id'] && $user_data['group_id'] != GROUPS_ADMIN && $user_data['group_id'] != GROUPS_MOD) { error('You do not have permission to edit this post!'); } if (!isset($_POST['submit'])) { $body->set('post', $post); $tpl->set('body', $body->fetch('post_edit.tpl.php')); } else { $ad_type = isset($_POST['ad_type']) ? check_input($_POST['ad_type']) : ''; $pet_type = isset($_POST['pet_type']) ? check_input($_POST['pet_type']) : ''; $breed = isset($_POST['breed']) ? check_input($_POST['breed']) : ''; $gender = isset($_POST['gender']) ? check_input($_POST['gender']) : ''; $colours = isset($_POST['colours']) ? check_input($_POST['colours']) : ''; $dob_day = isset($_POST['dob_day']) && is_numeric($_POST['dob_day']) && $_POST['dob_day'] > 0 && $_POST['dob_day'] <= 31 ? $_POST['dob_day'] : ''; $dob_month = isset($_POST['dob_month']) && is_numeric($_POST['dob_month']) && $_POST['dob_month'] > 0 && $_POST['dob_month'] <= 12 ? $_POST['dob_month'] : ''; $dob_year = isset($_POST['dob_year']) && is_numeric($_POST['dob_year']) ? $_POST['dob_year'] : ''; $dob = $dob_day . '|' . $dob_month . '|' . $dob_year; $available_day = isset($_POST['available_day']) && is_numeric($_POST['available_day']) && $_POST['available_day'] > 0 && $_POST['available_day'] <= 31 ? $_POST['available_day'] : ''; $available_month = isset($_POST['available_month']) && is_numeric($_POST['available_month']) && $_POST['available_month'] > 0 && $_POST['available_month'] <= 12 ? $_POST['available_month'] : ''; $available_year = isset($_POST['available_year']) && is_numeric($_POST['available_year']) ? $_POST['available_year'] : ''; $available = $available_day . '|' . $available_month . '|' . $available_year; $price = isset($_POST['price']) ? check_input($_POST['price']) : ''; $message = isset($_POST['message']) ? check_input($_POST['message']) : ''; $subscribe = isset($_POST['subscribe']) && $_POST['subscribe'] == 'yes' ? 'yes' : 'no'; $delete = isset($_POST['delete']) && $_POST['delete'] == 'yes' ? 'yes' : 'no'; if ($message == '') { error('Your message did not contain any content!'); } $db->query("DELETE FROM " . $config['db']['prefix'] . "forum_subscriptions WHERE user_id = $post[user_id] AND topic_id = $post[topic_id])"); if ($delete == 'yes') { output('Your post has been successfully deleted!'); if ($post['is_first'] == 1) { $result = $db->query("SELECT user_id FROM " . $config['db']['prefix'] . "forum_posts WHERE topic_id = $post[topic_id]"); while ($user = $db->fetch_array($result)) { $db->query("UPDATE " . $config['db']['prefix'] . "users SET num_posts = num_posts - 1 WHERE user_id = $user[user_id]"); } $db->query("DELETE FROM " . $config['db']['prefix'] . "forum_topics WHERE topic_id = $post[topic_id]"); $db->query("DELETE FROM " . $config['db']['prefix'] . "forum_posts WHERE topic_id = $post[topic_id]"); redirect('/forum/' . get_url_forum($post['forum_id'], $post['forum_name']), 2); } else { $db->query("DELETE FROM " . $config['db']['prefix'] . "forum_posts WHERE post_id = $post_id"); $db->query("UPDATE " . $config['db']['prefix'] . "forum_topics SET num_replies = num_replies - 1 WHERE topic_id = $post[topic_id]"); $db->query("UPDATE " . $config['db']['prefix'] . "users SET num_posts = num_posts - 1 WHERE user_id = $post[user_id]"); redirect('/forum/' . get_url_forum($post['forum_id'], $post['forum_name'], $post['topic_id'], $post['subject']), 2); } update_forum($post['forum_id']); } else { $db->query("UPDATE " . $config['db']['prefix'] . "forum_posts SET message = '$message' WHERE post_id = $post_id"); if ($subscribe == 'yes') { $db->query("INSERT INTO " . $config['db']['prefix'] . "forum_subscriptions (user_id, topic_id) VALUES ($post[user_id], $post[topic_id])"); } if ($post['is_first'] == 1) { $subject = isset($_POST['subject']) ? check_input($_POST['subject']) : ''; $topped = isset($_POST['topped']) && $_POST['topped'] == 'yes' && ($user_data['group_id'] == GROUPS_ADMIN || $user_data['group_id'] == GROUPS_MOD) ? 1 : 0; $db->query("UPDATE " . $config['db']['prefix'] . "forum_topics SET subject = '$subject', topped = $topped WHERE topic_id = $post[topic_id]"); } output('Your post has been successfully updated! Please wait while we redirect you to your post.'); redirect('/forum/' . get_url_forum($post['forum_id'], $post['forum_name'], $post['topic_id'], $post['subject'], $post_id), 2); } } } I have setup all the correct tables, and installed into MySQL and the data stores in the same place as 'message' but every time I use a different variable, eg. <?php echo $post['price']; ?> I get this error: Notice: Undefined index: price in /home/www/templates/forum/post_edit.tpl.php on line 132 Line 32 has this on it <?php echo $post['price']; ?> If anyone can spot what I am doing wrong I would really appreciate it. Been staring at my screen for hours trying to solve this Thanks, Paul Link to comment https://forums.phpfreaks.com/topic/193445--/ Share on other sites More sharing options...
New Coder Posted February 26, 2010 Share Posted February 26, 2010 Shouldn't you be using $_POST['price'] Link to comment https://forums.phpfreaks.com/topic/193445--/#findComment-1018425 Share on other sites More sharing options...
jpopuk Posted February 26, 2010 Author Share Posted February 26, 2010 Yeah, I have tried that also, but it still says "Notice: Undefined index: price in /home/www/templates/forum/post_edit.tpl.php on line 132" It baffles me, can't seem to figure it out which is driving me nuts! Link to comment https://forums.phpfreaks.com/topic/193445--/#findComment-1018426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.