staples27 Posted July 25, 2009 Share Posted July 25, 2009 I have this management system for a photo gallery and what I want to do is be able to add the year when I add the category, so I want it to add the gallery name and the year ( this is so the categories can appear in an ordered fashion ) How can I do this, I've tried various methods and tried implementing code from other insert forms I've used but no use the code is as follows <?php error_reporting(0); session_start(); if(!session_is_registered('users')){ header("location:login.php"); } ?> <?php include("config.inc.php"); if( empty($_POST['action']) ) { $result = mysql_query( "SELECT category_id,category_name,Year FROM gallery_category" ); while( $row = mysql_fetch_array( $result ) ) { $category_list .=<<<__HTML_END <option value="$row[0]">$row[1]</option>\n __HTML_END; } mysql_free_result( $result ); $category_list = '<select name="categoryid">'.$category_list.'</select>'; ?> <div id="maincontent"> <div class="hsection1"> <div class="title">Add Category:</div> <form name="add_category" action="mcategory.php" method="post"> Name: <input type="text" name="cname" /> <!-- add category year --> Year: <input type="text" name="year" /> <input type="submit" value="add" name="action" /> </form> </div> <div class="hsection1"> <div class="title">Edit Category:</div> <form name="edit_category" action="mcategory.php" method="post"> New Name: <input type="text" name="cname" /> <?php echo($category_list); ?> <input type="submit" value="edit" name="action" /> </form> </div> <div class="hsection1"> <div class="title">Delete Category:</div> <form name="delete_category" action="mcategory.php" method="post"> <?php echo($category_list); ?> <input type="submit" value="delete" name="action" /> </form> </div> </div> <?php } else { if( strcasecmp($_POST['action'], "add")==0 && !empty( $_POST['cname'] ) ) { add_category($_POST['cname']); } else if( strcasecmp($_POST['action'], "edit")==0 && !empty( $_POST['cname'] ) && !empty( $_POST['categoryid'] ) ) { edit_category($_POST['categoryid'], $_POST['cname']); } else if( strcasecmp($_POST['action'], "delete")==0 && !empty( $_POST['categoryid'] ) ) { delete_category($_POST['categoryid']); } else { echo("Action not understood"); exit; } echo("Process completed!"); } // the functions here function edit_category($category_id, $new_name) { mysql_query(" UPDATE gallery_category SET category_name = '" . addslashes($new_name) . "' WHERE category_id = '" . addslashes($category_id) . "'"); } function add_category($category_name) { mysql_query(" INSERT INTO gallery_category ( category_name ) VALUES ( '" . addslashes($category_name) . "' )"); } function delete_category($category_id) { global $images_dir; $result = mysql_query(" SELECT photo_filename FROM gallery_photo WHERE photo_category='" . addslashes($category_id) . "'"); while ($row = @mysql_fetch_array($result)) { unlink($images_dir . '/' . $row[0]); } mysql_query(" DELETE FROM gallery_photo WHERE photo_category='" . addslashes($category_id) . "'"); mysql_query(" DELETE FROM gallery_category WHERE category_id='" . addslashes($category_id) . "'"); } ?> Thanks for any help! Quote Link to comment Share on other sites More sharing options...
ignace Posted July 25, 2009 Share Posted July 25, 2009 Make sure year is of type YEAR: 'INSERT INTO gallery_category (category_name, Year) VALUES (' . addslashes($category_name) . ', ' . $year . ')' Quote Link to comment Share on other sites More sharing options...
staples27 Posted July 26, 2009 Author Share Posted July 26, 2009 hm that but didn't work, i've got it working now but thanks for the help Quote Link to comment 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.