473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Accessing variables on different pages

Hi, I am trying to build a shopping cart for my DVD website and am having
trouble reading variable over different pages.

I have a page that allows the user to add things to their cart and this page
also display what they have selected. I also am trying to build a 'checkout'
page that displays the DVDs they have chosen, the cost and allows them to
remove a DVD from their cart.

However, I can't even get the checkout page to display the list of DVDs that
is displayed on the other page. Globals variables have been turned off on
the server I am using.

Any help with this would be great.

Here is the code I was referring to:

<?php

// this section creates a session, connects to the db and handles the two
buttons being pressed.
session_start();
session_register("trolley");

require ('mysql.php');
mysql_connect ($host, $user, $passwd);
mysql_select_db ($dbName);

if (isset ($_GET['add']))
$_SESSION['trolley'][] = $_GET['add'];
else if ($_GET['op'] === 'clear')
$_SESSION['trolley'] = "";

$_GET['getdvds_query'];
$_GET['search_text'];
$_GET['search_in'];
$_GET['genrename'];
?>

<html>
<head>
<title>PHP & MySQL</title>
</head>

<table>
<?php

if ($search_in == "title") {
$getdvds_query = mysql_query ("SELECT dvdid, title, duration, rel, descr,
genre, stock, price FROM dvd where title LIKE '%$search_text%'");
}
else if ($search_in == "director") {
$getdvds_query = mysql_query ("select dvd.dvdid, dvd.title, dvd.duration,
dvd.rel, dvd.descr, dvd.genre, dvd.stock, dvd.price from dvd, director where
director.name like '%$search_text%'");
}
else if ($search_in == "actor") {
$getdvds_query = mysql_query ("select dvd.dvdid, dvd.title, dvd.duration,
dvd.rel, dvd.descr, dvd.genre, dvd.stock, dvd.price from dvd, actordvd,
actor where actor.actorid = actordvd.actorid and actordvd.dvdid = dvd.dvdid
and actor.name like '%$search_text%'");
}

else

$getdvds_query = mysql_query ("SELECT dvdid, title, duration, rel, descr, ge
nre, stock, price FROM dvd where genre LIKE '%$genrename%'");

if(!$getdvds_query) {
die("No result, error: ".mysql_error());
}

echo "<table bgcolor=\"ddeeff\"><thead><tr>";
for ( $i = 1 ; $i < mysql_num_fields($getdvds_query) ; $i++ ) {
echo "<th bgcolor=\"abcdef\">" .
mysql_field_name($getdvds_query,$i) . "</th>\n";
}

if ( mysql_num_rows($getdvds_query) > 0 )
{
while ( $row = mysql_fetch_assoc($getdvds_query) )
{
$dvd[$row['dvdid']] = $row;
echo "<tr>\n";
echo "<td>{$row['title']}</td>\n";
echo "<td>{$row['duration']}</td>\n";
echo "<td>{$row['rel']}</td>\n";
echo "<td>{$row['descr']}</td>\n";
echo "<td>{$row['genre']}</td>\n";
echo "<td>{$row['stock']}</td>\n";
echo "<td>{$row['price']}</td>\n";

echo "<td><a
href=\"start.php?main=search&add={$row[dvdid]}\">add to basket</a></td>";
echo "</tr>\n";
}
}

?>
</table>
<a href="start.php?main=search&op=clear">empty trolley</a><br /><br />
<a href="start.php?main=checkout&trolley<?=SID?>">Che ckout</a><br /><br />

<?php
//this section outputs basket contents
if (!empty ($_SESSION['trolley']))
{
echo 'Trolley contents:<br />';

foreach ($_SESSION['trolley'] as $trolley_item)
echo $dvd[$trolley_item]['title']."<br />";
}
else
echo 'Trolley is empty!';
?>

</body>
</html>

Here is my checkout page:

<?php

// this section creates a session, connects to the db and handles the two
buttons being pressed.
session_start();
session_register("trolley");
session_register("add");

require ('mysql.php');
mysql_connect ($host, $user, $passwd);
mysql_select_db ($dbName);

$_SESSION['trolley'];

if (!empty ($_SESSION['trolley']))
{

echo 'Trolley contents:<br />';
echo "<table bgcolor=\"ddeeff\"><thead><tr>";

foreach ($_SESSION['trolley'] as $trolley_item)
echo "<tr>\n";
echo $dvd[$trolley_item]['title']."<br />";
echo $dvd[$trolley_item]['price']."<br />";
echo "</tr>\n";
}
else
{
echo 'Trolley is empty!';
}

?>


Jul 17 '05 #1
2 2548
James wrote:
(snip)
Any help with this would be great.

Here is the code I was referring to:

<?php
// make PHP report the use of unintialized variables
error_reporting(E_ALL);
ini_set('display_errors', '1');

// this section creates a session, connects to the db and handles the two
buttons being pressed.
session_start();
session_register("trolley");
http://www.php.net/session_register

Caution: If your script uses session_register() it will not work in
environments where the PHP directive *register_globals* is disabled.
(snip)</table>
<a href="start.php?main=search&op=clear">empty trolley</a><br /><br />
<a href="start.php?main=checkout&trolley<?=SID?>">Che ckout</a><br /><br />

_________________________________^^^^^^^^^^^^^^^^

Something like "&trolleyfedcba9876543210fedcba9876543210" ?
Are you perhaps missing a '=' after "trolley" ?

(snip)
You have quite a few statements without effect throughout your code:

<?php

$_GET['id']; // statement without effect
// AFAICT this does absolutely nothing

?>
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
Pedro, thanks for your advice. It's a bit late now but I'll work on the code
some more tomorrow. If anyone else has any more help I would be very
grateful.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James | last post by:
Hi, I am trying to build a shopping cart for my DVD website and am having trouble reading variable over different pages. I have a page that allows the user to add things to their cart and this...
5
by: Larry Woods | last post by:
I am losing Session variables, but only those that are set in the page previous to a redirect to a secure page. Anyone seen ANY situation where Session variables just "disappear?" Note that...
2
by: Earl Teigrob | last post by:
I am programming ASP.NET using C#. I have been accessing static variables accross my entire application but now need to change some of the static variables that are session specific to instance...
1
by: Salek Talangi | last post by:
Hello, I have following (probably very basic) problem: I made a html-frameset in VS.net, where the frames itself are aspx-pages with webforms. Now I want to access the webforms (eg. give a label...
3
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
8
by: e_matthes | last post by:
Hello, I keep reading that $_SERVER can easily be faked. Is that true of all server variables, or just some of them? In particular, I'm wondering if server_port can be faked. I'm interested...
5
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the...
2
by: brendan_gallagher_2001 | last post by:
HI I am developog an ASP.net site (using vb.net 1.1) which will be accessed by a number of different office locations, where certain users will be assigned a authoriser profile, and others will...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.