0

hi all im a little new to php code i has searched a lot of site in hope of being able to work this one out and now im stuck.

i have a page for a product on it and the php file for it is

<?php
//******************************
//Custom Code for getting data
//******************************

if (!$_REQUEST['pid']){
	echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?xps=pindex'>";
	exit();
} else {
	$pids = explode("-", $_REQUEST['pid']);
	$_REQUEST['pid'] = $pids[0];
}
$product = $myItems->getAll("single", $_REQUEST['pid']); //get the products data from the database

$pv_array = explode(",", $product[$_REQUEST['pid']][variations]);

$i=0;
$totalpvs = 0;
$result = $myDB->query_select("SELECT * FROM " . $config['table_product_var']);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
	if (in_array($row['ID'], $pv_array)) {
		$pv[$i][title] = $row['title'];
		$options_array = explode(", ", $row['options']);
		$counter = $i;
		$optionhtml = "<select name=\"pv_{$i}\">";
		for ($j = 0; $j < sizeof($options_array); $j++) {	
			$optionhtml .= "<option value=\"{$options_array[$j]}\">{$options_array[$j]}</option>";
		}
		$optionhtml .= "</select>";
		$pv[$i][options] = $optionhtml;
		$totalpvs++;
		$i++;
	}
}

$result = $myDB->query_select("SELECT * FROM " . $config['table_product_types'] . " WHERE Id = '" . $product[$_REQUEST['pid']][type] . "'");			
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$customfields = $row['customfields'];

$cf_array_labels = explode("|", $customfields);
$cf_array_data = explode("|", $product[$_REQUEST['pid']][customdata]);

for ($i=0; $i<sizeof($cf_array_data); $i++) {
	if ($cf_array_data[$i]) {
		$customdata[$i][label] = $cf_array_labels[$i];
		$customdata[$i][data] = $cf_array_data[$i];
	}
}

//******************************
//Template Code below this point
//******************************

$pagetpl = new template; 			//Creates a new instance of the template class for this page
$pagetpl->set_template($page_url, "[", "]"); 	//Sets the tpl (template) file and the prefix and sufix characters

//Theses are all the varibles that we can use in the tpl file.
$pagetpl->set_var('SKINDIR', './templates/' . $config['skin_id'] . '/images');
$pagetpl->set_var('USERID',		$user_id); 

$pagetpl->set_var('PDBID',		$product[$_REQUEST['pid']][pid]);   
$pagetpl->set_var('PID',		$product[$_REQUEST['pid']][product_id]);   
$pagetpl->set_var('PNAME',		$product[$_REQUEST['pid']][name]);   
$pagetpl->set_var('PDESCRP',	$product[$_REQUEST['pid']][descrip]);   
$pagetpl->set_var('PCOST',		$product[$_REQUEST['pid']][cost]);  
if ($product[$_REQUEST['pid']][saleprice] == "0.00") {
	$product[$_REQUEST['pid']][saleprice] = "";
}
if (($product[$_REQUEST['pid']][rrp] != "0.00")  || ($product[$_REQUEST['pid']][rrp] != "")){ 
	if ($product[$_REQUEST['pid']][saleprice]) {
	$product[$_REQUEST['pid']][cost] = $product[$_REQUEST['pid']][saleprice];	
	} else {
		
	}
	$pagetpl->set_var('PDIF',		$product[$_REQUEST['pid']][rrp]-$product[$_REQUEST['pid']][cost]);  
	
	if ($product[$_REQUEST['pid']][rrp] > 0) {
		$savings = ($product[$_REQUEST['pid']][rrp]-$product[$_REQUEST['pid']][cost]);
		$percent = round( ($savings/$product[$_REQUEST['pid']][rrp])*100, 0 );
		$pagetpl->set_var('PPER',		$percent); 
	} else {
			$product[$_REQUEST['pid']][rrp] = "N/A";
			$pagetpl->set_var('PPER',		"N\A"); 
			$pagetpl->set_var('PDIF',		"N/A");	
	}
} else {
	$product[$_REQUEST['pid']][rrp] = "N/A";
	$pagetpl->set_var('PPER',		"N/A");  
	$pagetpl->set_var('PDIF',		"N/A");		
}
 
$pagetpl->set_var('PRRP',			$product[$_REQUEST['pid']][rrp]);  
$pagetpl->set_var('PNP',			$product[$_REQUEST['pid']][pnp_cost]); 
$pagetpl->set_var('PIMG',			$C->imageviewer("pimgviewer", $_REQUEST['pid']));  
$pagetpl->set_var('ADDED',			$product[$_REQUEST['pid']][add_to_cart]);  
$pagetpl->set_var('VIEWS',			$product[$_REQUEST['pid']][views]);  
$pagetpl->set_var('USERID',			$user_id);   
$pagetpl->set_var('loggedin', 		$C->logictest($user_id), '', TRUE);	//if statement
$pagetpl->set_var('loggedin2', 		$C->logictest($user_id), '', TRUE);	//if statement
$pagetpl->set_var('shopstatus', 	$C->logictest($config['shop_status'], 0), '', TRUE);	//if statement
$pagetpl->set_var('OFFLINEMSG',		$config['offline_message']);  

$pagetpl->set_var('customdata',		$customdata, 	''); 
if ($product[$_REQUEST['pid']][saleprice] == "0.00" ) { $product[$_REQUEST['pid']][saleprice] = ""; }

$pagetpl->set_var('saleprice', 		$C->logictest($product[$_REQUEST['pid']][saleprice]), '', TRUE);	//sets up the empty cart if statement
$pagetpl->set_var('SALECOST',		$product[$_REQUEST['pid']][saleprice]);  

$pagetpl->set_var('item_pnp_value', $C->logictest($product[$_REQUEST['pid']][pnp_cost]), '', TRUE);	//if statement
$pagetpl->set_var('item_pnp', 		$C->equalto($config['pnptype'], 2), '', TRUE);

$pagetpl->set_var('stocklevel', 	$C->equalto($product[$_REQUEST['pid']][stock], 0), '', TRUE);	//if statement
$pagetpl->set_var('STOCK',			$product[$_REQUEST['pid']][stock]);  

$pagetpl->set_var('pv',				$pv, 	''); 
$pagetpl->set_var('TOTALPV',		$totalpvs);
$pagetpl->set_var('REVIEWS',		$myItems->_getproductreviews($_REQUEST['pid'], '', "reviews"));  
$pagetpl->set_var('rrp', 			$C->equalto($product[$_REQUEST['pid']][rrp], '0.00'), '', TRUE);	//if statement

//This draw the page with all its changes to the screen.
$pagetpl->parse();
$content =  $pagetpl->draw();
?>

i want to pass the = $pids value to the next page which is just a html page at the mo and it contains an email form where i need the value to be copied. i have tried passing it via the url using GET command and all i get is errors or it just does nothing. im hoping some one can help or point me in the right direction.

thanks all

4
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by Setvir
0

Rather than using $_REQUEST['pid'] try using $_POST['pid'] if the form method is post or $_GET['pid'] if the form method is get.

Edited by Setvir: n/a

0

Change the page extension to .php. Your php code (for $_GET) will then work. Unless you specifically make it so (htaccess), html files cannot run php code.

0

im sure one of thoes is the correct answer unfortunately im at a simpler stage than that. im not sure how to go about putting that on the page it directs you to. do i just simply make a PHP file with the same name and direct it to that page with that code on the page or would i need a lot more code?

thanks for helping guy and girls

0

I disagree that putting html affects the php code. Just start with php tags (<?php .......?>). That being said you need to have a session variable that will be passed to the other page in the same session. Read about sessions in PHP manual.

0

im sending this variable to a box in a form not taking it from a form does this make a difrence?

0

Sending to a box and taking it makes difference. Taking it from a form you use $_POST/$_GET and Sending it just take it from $_SESSION superglobal array and echo it

<input type="text" value=<?php echo $_SESSION['MyVariable']?> />
0

I disagree that putting html affects the php code. Just start with php tags (<?php .......?>).

Html files won't run php, unless specifically told to do so, e.g. from .htaccess files:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
0

Html files won't run php, unless specifically told to do so, e.g. from .htaccess files:

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

May be you are right but I have never used any .htaccess and have used HTML embedded with php. Does WAMP server come with htaccess set?
I have never took trouble and things are ok!

0

There are a few ways of doing this.
On your sending page:
Send the variable from a form:

use method post or get for form

<input type="hidden" name="date" value="<?php echo $date; ?>" \>

or by setting sending it in a url

< a href="nexpage.php?date=<?php echo urlencode($date); ?>" \>

or by setting a session variable

$_SESSION['date']= $date;

Then on nexpage.php:

if sent from a form with the post method

$date=$_POST['date'];

if sent from a form using get method
or as part of the url

$date=$_GET['date'];

or if your session is set

$date=$_SESSION['date'];

Hope it helps!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.