Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Passing an ID from page to page

Enthusiast ,
Aug 02, 2010 Aug 02, 2010

Copy link to clipboard

Copied

Hope someone can help with this....

I have a database structure along the lines of :

1. A main table of holiday packages.

2. A table of destinations that form a many to many link with the Packages table.

3. A table of feature types (eg museums, theme parks) that form another many to many link with the Packages table.

First I have a page addPackage.php. This goes onto addPackageDestinations.php, which inserts the data entered in the addPackage page, and grabs the package_ID of that new record :

------------------------

<?php

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

/********************

*

*insert Package details into db

*

********************/

//sql string

$insertSQL = sprintf("INSERT INTO packages (package, costperpax, duration, baselocation, category, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, themepark, museum, rollingtours, seminars, historicsite, teambuilding, zoo, park, church, naturalbeauty, relaxation, beach, city, wildlife, international, mallshopping, description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

GetSQLValueString($_POST['package'], "text"),

GetSQLValueString($_POST['costperpax'], "text"),

GetSQLValueString($_POST['duration'], "date"),

GetSQLValueString($_POST['baselocation'], "text"),

GetSQLValueString($_POST['category'], "text"),

GetSQLValueString($_POST['agerange'], "text"),

GetSQLValueString($_POST['hotel'], "text"),

GetSQLValueString($_POST['educational_tours'], "text"),

GetSQLValueString($_POST['field_trips'], "text"),

GetSQLValueString($_POST['corporate_outings'], "text"),

GetSQLValueString($_POST['plant_visits'], "text"),

GetSQLValueString($_POST['budget_package'], "text"),

GetSQLValueString($_POST['themepark'], "text"),

GetSQLValueString($_POST['museum'], "date"),

GetSQLValueString($_POST['rollingtours'], "text"),

GetSQLValueString($_POST['seminars'], "text"),

GetSQLValueString($_POST['historicsite'], "text"),

GetSQLValueString($_POST['teambuilding'], "text"),

GetSQLValueString($_POST['zoo'], "text"),

GetSQLValueString($_POST['park'], "text"),

GetSQLValueString($_POST['church'], "text"),

GetSQLValueString($_POST['naturalbeauty'], "text"),

GetSQLValueString($_POST['relaxation'], "text"),

GetSQLValueString($_POST['beach'], "text"),

GetSQLValueString($_POST['city'], "text"),

GetSQLValueString($_POST['wildlife'], "text"),

GetSQLValueString($_POST['international'], "text"),

GetSQLValueString($_POST['mallshopping'], "text"),

GetSQLValueString($_POST['description'], "text"));

//insert

$Result1 = mysql_select_db($database_connPackages, $connPackages); mysql_query($insertSQL); echo mysql_error();

/********************

*

*Retrieve package_ID

*

********************/

$package_ID = mysql_insert_id ();

?>

-------------------------

So far, so good.

I then go onto an addPackageFeatures.php page, which inserts the package destinations like so :

-----------------------

<?php

/********************

*

*insert Package Destinations into PackageDestinations table table

*

********************/

//sql insert string

$sql = "INSERT INTO packagedestinations (packageID, destinationID) VALUES ";

$ck = $_GET['ckbox'];

//loops though the profiles adding the the insert string each profile row

foreach ($ck As $GetIndex => $GetValue){

if ($GetValue=='on'){

$sql .= "('{$_GET['package_ID']}', '$GetIndex'), ";

}

}

//trims the end ,

$sql = rtrim($sql," ,") ;

//inserts data

mysql_select_db($database_connPackages, $connPackages); mysql_query($sql); echo mysql_error();

?>

----------------------

So all I need on this page is the same package_ID for the new package being created, to be passed from the addPackageDestinations page onto the addPackageFeatures page.

Not sure how well I've explained it but hopefully it makes sense...?

Thanks.

TOPICS
Server side applications

Views

419
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 02, 2010 Aug 02, 2010

Copy link to clipboard

Copied

pass ID from page to page using one of these techniques:

get, post, cookie, session variable, info stored/retrieved from database

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 02, 2010 Aug 02, 2010

Copy link to clipboard

Copied

Not sure why, but this is something I always have a mental block with - what form would the syntax take for that?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 03, 2010 Aug 03, 2010

Copy link to clipboard

Copied

LATEST

All working now.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines