Jump to content

create dropdown select from database


seanstuart

Recommended Posts

this is how the origonal script looks at add_menu_item.php... and edit_menu_item.php will i have to these and how would i call it?

 

<?php
require_once("access.php");
require_once(LIB_PATH."Restaurant.php");
require_once(LIB_PATH."Menu.php");
require_once(LIB_PATH."MenuSection.php");
require_once(LIB_PATH."MenuItem.php");

$restaurant_id = Sanitize::data($_GET['restaurant_id'], "integer");
$menu_id = Sanitize::data($_GET['menu_id'], "integer");
$section_id = Sanitize::data($_GET['section_id'], "integer");

if($restaurant_id == 0){
$error_message = "You must select a restaurant, prior to be able to add a menu item!";
}elseif($menu_id == 0){
$error_message = "You must select a menu, prior to be able to add a menu item!";
}else{

$restaurant_obj = new Restaurant($restaurant_id);

if($restaurant_obj->user_id == $_SESSION['logged_user_id']){

	$menu_obj = new Menu($restaurant_id);

	//get the menu sections
	$menu_sections = MenuSection::allMenuSections($menu_obj->menu_id);

	if(multiArraySearchValue($menu_sections, 'section_id', $section_id) >= 0){

		/**
			* Determinate does the form was submited.
 		*/
		if($_SERVER['REQUEST_METHOD'] == "POST"){

			/**
 			* Intance the restaurant object
	 		*/
			$mi_obj = new MenuItem();

			/**
 			* Sanitize the posted values.
	 		*/
			$item_name = Sanitize::data($_POST['item_name'], "string");
			$item_description = Sanitize::data($_POST['item_description'], "string");
			$item_price = Sanitize::data($_POST['item_price'], "float");
			$item_order = Sanitize::data($_POST['item_order'], "string");
			$section_id = Sanitize::data($_POST['section_id'], "integer");

			/**
 			* Set the object properties.
	 		*/
			$mi_obj->setMember("item_name", $item_name);
			$mi_obj->setMember("item_description", $item_description);
			$mi_obj->setMember("item_price", $item_price);
			$mi_obj->setMember("item_order", $item_order);
			$mi_obj->setMember("section_id", $section_id);

			/**
	 		* Try to add the new menu section to the database.
 			*/
			if($mi_obj->add($error_message)){
				/**
		 		* Redirect the user to the "thank you" page.
		 		*/
				header("location: restaurant.php?id=$restaurant_id");
				exit;
			}
		}
	}else{
		//this menu section do not belongs to the current logged user
		$error_message = "You must create at least one menu section, prior to be able to add a menu item!";
	}
}else{
	//this menu restaurant do not belongs to the current logged user
	header("location: index.php");
	exit;
}


if(!	$item_status) $item_status = 1;

/**
 * Get the menu sections array.
 */
$menu_sections = MenuSection::allMenuSections($menu_id);
$select_section = get_select_box_db('0', $section_id, "section_id", $menu_sections, 'section_name', 'section_id', '---select---', 'base', '');

}

$form_title = "Add a new menu item";

$website_title = "Add menu item - ".$_SESSION['settings']['site_title'];
$website_description = $_SESSION['settings']['site_description'];
$site_keywords = $_SESSION['settings']['site_keywords'];

require_once(WEB_TEMPLATES."HeaderTemplate.php");
require_once(WEB_TEMPLATES."MenuItemManageTemplate.php");
require_once(WEB_TEMPLATES."FooterTemplate.php");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.