Forum Moderators: coopster

Message Too Old, No Replies

Setting Variable as another Variable

Newbie in need of help

         

GGR_Web

9:16 am on Oct 21, 2008 (gmt 0)

10+ Year Member



Hi
I'm trying to set up google analytics to use the ecommerce tools.
I have everything set up apart from using values that Google reconises.
I'm almost brand new to php so could someone tell me if this is valid code?
Cheers!

<!--Convert Our $Varables to $Varables Google Understands -->
$order-id = <!--Our Order Number $Varable-->
$unit price = <!-- Our Unit Price $Varable-->
$quantity = <!-- Our Quantity $Varable-->

<!--google tracking begins-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-#*$!#*$!-x");
pageTracker._trackPageview();
</script>

<!--google ecommcerce tracking begins-->
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);

pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);

pageTracker._trackTrans();
</script>

Edit: Is the segment at the top going to set the varibles for order-no, unit price ect?

Edit: Would this have to go under the definations for our own varables?

[edited by: GGR_Web at 9:40 am (utc) on Oct. 21, 2008]

andrewsmd

5:56 pm on Oct 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this your exact code. If so you need a <?php when you set php variables, just as you need a script type="text/javascript"> i.e.
<?php
$order-id = <!--Our Order Number $Varable-->
$unit_price = <!-- Our Unit Price $Varable-->
$quantity = <!-- Our Quantity $Varable-->
?>
However if you want these to show up in your HTML code you need to echo them
Also note the _ in unit price you can't name a variable with a space.

<?php
$order-id = <!--Our Order Number $Varable-->
$unit_price = <!-- Our Unit Price $Varable-->
$quantity = <!-- Our Quantity $Varable-->
echo($order-id.$unit_price.$quantity);
?>

However if you are trying to use these with JavaScript JS won't recognize your PHP. If you want to use strictly JS post on the JS forum.

If you can be more specific then I can help more.

GGR_Web

7:58 am on Oct 22, 2008 (gmt 0)

10+ Year Member



I'm just trying to set up the google analytics ecommerce tools!

Unfortunatly I've been recieving conflicting advice/information about how to do it.

I thought Javascript could read php - then how do I call these values correctly?

This is going into a pre-existing php file. I'm told this code needs to be immedialy before the
</body> tag, which is very unhelpful as the vaules I need to refer to are below the tag, which
means the browser won't reconise them currently. I don't dare to move the </body> tag down as I don't
know what effects this will produce (in standard html I'd end up with code all down the page) - this page
is mission critical.

Could I possibly use a seperate php file to prepare the varables I require and call them at the appropiate point? Would this action cause the system to skip to the requested values while proccessing the call?

Actually, while I'm thinking about this, would it make more sense to dump the whole lot I posted into its own php and simply call it before the </body> tag and call my values seperately there?

I think I'll try that :)

Feel free to reply if any of this makes sense

[edited by: GGR_Web at 8:11 am (utc) on Oct. 22, 2008]

andrewsmd

1:01 pm on Oct 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know who you were talking to but you can put php anywhere in the html you want and then the browser will see it as HTML. The reason being PHP is parsed by your php server so when you put PHP in an html file, your server parses it and sends the output of your code in html to the client that has requested your site. You do have a PHP server set up correct. If so I'll give you an example. Open a file and name it anything you want with a .php extension. For the sake of simplicity I will call it test.php
paste this code in and then look at the page
<html>

<?php

//note that none of this php will be outputted
//until I call it later.

//here is an example php function with a variable
//passed into it
function helloWorld($message){

echo("<p>$message</p>");

}//helloWorld

//another example function
function doSomething(){

$var = 5;
$var2 = 6;
echo("{$var} + {$var2} = ".($var+$var2));

}//doSomething

?>

<body>

<center><h1>Now let's show you some examples</h1></center>

<?php
echo("<p>Here is the first occurence of PHP. Notice I didn't call anything at all</p>");

$hw = "Hello World";
echo("<p>$hw</p>");
?>

<h2>This is some more HTML</h2>

<?php
//now we will call some functions
helloWorld("<br>This was the message we passed into the first function");

doSomething();

//echo a line break
echo("<br>");

//call the function from the bottom of the page
forLoopExample();
?>

<p>And some final HTML.</p>

</body>

<?php

//this is just showing you can put php anywhere
//we called the first functions from the top
//and this one from the bottom
//it gets put in the page wherever you call it

//an example for loop
function forLoopExample(){

for($i = 0; $i < 10; $i++){

echo("<center>$i</center>");

}

}//forLoopExample

?>
</html>

open up the source and notice you don't see any PHP just html. I hope this helps let me know if you need more clarification. If you can be specific on your problem i.e. exact details on what you want to do I can probably help you code it.

andrewsmd

1:12 pm on Oct 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, if you want to put your php code in an external file you can but you still have to have php in the original i.e. you have yourFile.php and the page the user goes to somePage.php
in somePage.php you would have the code
<?php
require_once("yourFile.php");
?>
Then you can call functions just like I did in the previous example. However, you cannot call variables unless you declare them as global, but I would not recommend that as you are a beginner and that can cause a big headache for even the best PHP programmers. Unless your going to have a massive amount of code, and since you have to write php to call it, I would just have it all in one file. If it's too big for that then you would want to look into using HTML templates with PHP, which is a whole different ball game.

GGR_Web

4:35 pm on Oct 22, 2008 (gmt 0)

10+ Year Member



Just to let you know I have read this - but its 5:30 and I'm clocking off, so I'll try your code in the morning.
From what you say, this should be eaiser than I thought :)

So a $Variable can be called regardless of it's place in the code, correct?

Thanks for your help, frankly this is a bit beyond me.

andrewsmd

5:12 pm on Oct 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As long as you define the variable before you call it. I.E. if you have
<html>
<?php
$var = "Hello World";
?>
<body>
<?php
echo($var);
?>
</body>
</html> Then you will get a page with "Hello World"
However if the order is reversed.
<html>
<?php
echo($var);
?>
<body>
<?php
$var = "Hello World";
?>
</body>
</html>
You will not get anything because $var is not defined yet. If you want to put it at the end and call it before then you need to put it into a function like I posted earlier. Functions can be called no matter where they are in your code because when you call a function like
callFunc();
in your code that is telling the server Hey keep your spot in this HTML but go to this code and output what it says. Of course callFunc can be whatever you named your function.

GGR_Web

7:57 am on Oct 23, 2008 (gmt 0)

10+ Year Member



So if I do this

<html>
<?php
function Write (echo $words)
$words = "99 bottles of milk";
?>
<body>
Write();
</body>
</html>

or this

<html>
$words = "99 bottles of milk";
<body>
Write();
</body>
<?php
Function Write (echo $words)
?>
</html>

Or Even...

<html>
<body>
Write();
</body>
$words = "99 bottles of milk";
<?php
function Write (echo $words)
?>
</html>

I will return "99 bottles of milk as on screen text in every case, where I called the Write function?

No, tried using these bits of code without success. Care to debug? :)

[edited by: GGR_Web at 8:53 am (utc) on Oct. 23, 2008]

GGR_Web

10:53 am on Oct 23, 2008 (gmt 0)

10+ Year Member



Maybe I should just send you the 2 segments of code I'm supposed to be getting to work together

andrewsmd

11:40 am on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes send me the code I can probably fix it for you rather quickly. As far as your functions the () are for variables you pass into it. What I mean is if you want to call a function but use some current values you have locally then you set it with a variable like this function($variable) DON'T FORGET THE { ! All functions are structured like this...
function functionName($someOptionalVariable, $someOptionalVaribale2){
do some code
do as much code as you want
until you see this
}//end of functionName
Also, in the parenthesis you can leave them blank and not pass anything. Remember how the variable has to be defined before you can use it. Well most functions come after you call them or may even be in another file. That is why you have arguments (the variables in parenthesis) that we pass into them. You can have none or as many as you want. A good example of why we need functions can be explained like this. I work a lot with file paths i.e. c:\some folder\some file.txt. Now there are many times when I need to get just the file name (some file.txt). It only takes about 10 lines of code but I need to do it all the time. So I created a function that does it and returns the value for me. The only thing that changes is the file path so in the function getFileName($filePath) I pass in $filePath when I call it. Meaning when I write getFilePath("C:\some folder\some file.txt"); then within the function $filePath now = "C:\some folder\some file.txt" now on the next line I could call it again getFileName("C:\a different folder\a different file"); and within getFileName $filePath now = "C:\a different folder\a different file" For what you want I don't think we will even need functions so lets not worry about them now. Just paste the code you need to work and try to explain what exactly it needs to do. As far as your debugging.
<html>
<?php
//since you define $words within the
//function we don't need to pass it in
function Write(){
//all of your actual code
//must be within {} the ()
//are just for variables
$words = "99 bottles of milk";
echo($words);
}//Write
?>

<html>
<?php
$words = "99 bottles of milk";
//every time you want to do
//anything in php
//you need to have the <?php
//otherwise the browser will
//just see it as HTML
?>
<body>
<?PHP
Write($words);

//I'm just showing you
//that something else can
//go in Write
Write("The second text");

$thirdText = "The third text";

Write($thirdText);
?>
<body>
<?php
Function Write($words){
echo("Words is {$words} because that is what you passed in. <br>");
}
?>
</html>

<html>
<body>
Write();
</body>
</html>

<html>
<body>
Write();
</body>

<?php
$words = "99 bottles of milk";
function Write($words){
echo($words);
}
However this last one will give you nothing because all variables have local scope unless you define otherwise. Like I said earlier let's not worry about functions right now just paste your code and tell me what it needs to do. I can debug it for you.
?>
</html>

andrewsmd

11:58 am on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One last note in your function write() don't think of $words as within the funciton. What I mean is think of it this way. You have a function write and it's job is to echo something. Now it doesn't know what to echo until you tell it. So maybe defining it like this would make more sense to you
function Write($temporaryVariable){

echo($temporaryVariable);

}
now when you type
Write("Hello World");
you are saying hey Write you are supposed to echo $temporaryVariable and right now it equals "Hello World"
then when you type
$words = "the words";
Write($words);
you are saying hey Write you are supposed to echo $temporaryVariable and now it equals $words function Write says ok what does $words equal and then it says ok it equals "the words" so it echoes that. I hope it wasn't too lengthy for you. There is just now short way to explain programming. Just paste your code.

GGR_Web

2:11 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Sorry mods :) These are the php code files I need to get working together. I need to figure a way to get the first bit to use some values from the second. I imagine everyone reading can do this in their sleep, but there we go.

<?
<script type="text/javascript">
</script>
<!--Call requested Data from Our mySQL databases and define it as varables-->

<!--google code-->
<!--google tracking begins-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-#*$!#*$!x-1");
pageTracker._trackPageview();
</script>

<!--google ecommcerce tracking begins-->
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);

pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);

pageTracker._trackTrans();
</script>
<!--End of Google Tracking-->
<!-- Do not add code here -->
?>

GGR_Web

2:13 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



And this is the second bit - sorry can't chop it down very easily since I don't know what is relevant in this case.

<HTML><TITLE>Checkout Confirmation</TITLE>
<link rel="stylesheet" href="css/stm56_stylesheet.css" type="text/css">
<script language="javascript" type="text/javascript">
if (self != top) {
if (document.images)
top.location.replace(window.location.href);
else
top.location.href = window.location.href;
}
</script>
</HEAD>
<BODY bgcolor="#FFFFFF" text="#000000" link="#CC0000" vlink="#999999" alink="#CC0000">
<p>Unfortunately your credit card has not been authorised.</p>
<br><br><a href="http://www.example.com/">Return Home</a>

</body>
</html>
<?
}
else
{

$status1 = "cancel";

if($orderid){
if($result = mysql_query("SELECT orderlist FROM temporder WHERE id=$orderid")){
if(mysql_num_rows($result) == 1){
if(isset($ggrsale)){
if($bits = explode(" ",$ggrsale)){
$query = "SELECT * FROM ggrdetails1 WHERE id=".$bits[0]." AND cookiecode='".$bits."'";
if($result1 = mysql_query($query)){
if(mysql_num_rows($result1) == 1){
$userdetails = mysql_fetch_array($result1);
$status1 = "account";
$userid = $bits[0];
}else{
$status1 = "cancel";
}
}else{
$status1 = "cancel";
}
}else{
$status1 = "cancel";
}
}else{
$status1 = "cancel";
}
$row = mysql_fetch_array($result);
$shoppingbasket = $row['orderlist'];
if(ereg(",",$shoppingbasket)){
$shoppinglist = explode(",",$shoppingbasket);
}else{
$shoppinglist[0] = $shoppingbasket;
}
$status1 = "go";
}
}
}
include("functions.php");
?>
<HTML><TITLE>Checkout Confirmation</TITLE>
<link rel="stylesheet" href="css/stm56_stylesheet.css" type="text/css">
<script language="javascript" type="text/javascript">
if (self != top) {
if (document.images)
top.location.replace(window.location.href);
else
top.location.href = window.location.href;
}
</script>
</HEAD>
<BODY bgcolor="#FFFFFF" text="#000000" link="#CC0000" vlink="#999999" alink="#CC0000">
<?
if($status1 == "cancel"){
?>
There is an error with the data passed to the page.
<?
}else{
mysql_select_db(stock);
?>
<p>Welcome - Address - Pay - <b>Confirm</b></p>
<table bgcolor="white"><tr><td class="index610">
<table border="0" cellspacing="0" cellpadding="0" width="590" bgcolor="white">
<tr class="underdash">
<td valign="top" class="fumbnail2"><p class="header_o">Part no.</p></td>
<td valign="top" class="fumbnail2"><p class="header_o">Description</p></td>
<td valign="top" class="fumbnail2"><p class="header_o">Quantity</p></td><td valign="top" class="fumbnail2"><p class="header_o">Subtotal</p></td></tr>
<?
$query = "SELECT partno,name,price FROM product WHERE ";
for($i=0;$i<count($shoppinglist);$i++){
if($equalpos = strpos($shoppinglist[$i],"=")){
$lastlistpart[$i] = substr($shoppinglist[$i],0,$equalpos);
$lastlistqnty[$i] = substr($shoppinglist[$i],$equalpos+1);
$lastliststatus[$i] = "no";
$query .= "partno='".substr($shoppinglist[$i],0,$equalpos)."'";
if($i != (count($shoppinglist)-1)){
$query .= " OR ";
}
}
}
$totalprice = 0;
if($query != "SELECT partno,name,price FROM product WHERE "){
if($result = mysql_query($query)){
$ii = 0;
while($row = mysql_fetch_array($result)){
$quantity = 0;
for($i=0;$i<count($shoppinglist);$i++){
if($row['partno'] == $lastlistpart[$i]){
$quantity = $lastlistqnty[$i];
$lastliststatus[$i] = "yes";
}
}
$partnumber[$ii] = $row['partno'];
$partquantity[$ii++] = $quantity;
$emailshoppinglist .= $quantity." \t".$row['partno']." ".stripslashes($row['name'])." \t".pounds_pence($quantity * $row['price'])."\n";
?>
<tr>
<td valign="top" class="fumbnail2"><?=$row['partno']?></td>
<td valign="top" class="fumbnail2"><?=stripslashes($row['name'])?></td>
<td valign="top" class="fumbnail2"><?=$quantity?></td>
<td valign="top" class="fumbnail2"><?=pounds_pence($quantity * $row['price'])?></td></tr>
<?
$totalprice += $quantity * $row['price'];
}
}

if(in_array("no",$lastliststatus)){
$emailshoppinglist .= "These are items you have ordered which are not listed online. Costs are not included in the total price\n";
?>
<tr><td colspan="4">* Below are ordered items which are not listed on the online database.
<br />The prices are not available and are not included in the total price.
<br />Please contact us for the full cost of your order.</td></tr>
<?
for($i=0;$i<count($lastliststatus);$i++){
if($lastliststatus[$i] == "no"){
$emailshoppinglist .= $lastlistqnty[$i]." \t".$lastlistpart[$i]." \tTBC\n";
$partnumber[$ii] = $row['partno'];
$partquantity[$ii++] = $quantity;
?>
<tr>
<td valign="top" class="fumbnail2"><?=$lastlistpart[$i]?></td>
<td valign="top" class="fumbnail2">Not listed in the online database*</td>
<td valign="top" class="fumbnail2"><?=$lastlistqnty[$i]?></td>
<td valign="top" class="fumbnail2">POA</td></tr>
<?
}
}
}
?>

<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>Total :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=pounds_pence($totalprice)?></b></p></td></tr>
<?
if($delivery == "Standard"){
$deliveryfigure = 500;
$emailshoppinglist .= "\tDelivery (UK mainland)\t".pounds_pence($deliveryfigure)."\n";
?>
<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>UK Mainland Delivery :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=pounds_pence($deliveryfigure)?></b></p></td></tr>
<?
}else{
$deliveryfigure = 0;
$emailshoppinglist .= "\tDelivery (".$delivery.")\tTBC\n";
?>
<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>Delivery :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=$delivery?></b></p></td></tr>
<?
}
if($tax == "EC"){
$taxfigure = ceil(($totalprice+$deliveryfigure)*0.175);
$emailshoppinglist .= "\tVAT\t".pounds_pence($taxfigure)."\n";
?>
<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>VAT :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=pounds_pence($taxfigure)?></b></p></td></tr>
<?
}else{
$taxfigure = 0;
$emailshoppinglist .= "\tVAT\t£0.00\n";
}
if($delivery == "Standard"){
$emailshoppinglist .= "\tFull Total\t".pounds_pence($totalprice+$deliveryfigure+$taxfigure)."\n";
?>
<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>Full Total :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=pounds_pence($totalprice+$deliveryfigure+$taxfigure)?></b></p></td></tr></table>
<?
}else{
$emailshoppinglist .= "\tTotal not including delivery\t".pounds_pence($totalprice+$taxfigure)."\n";
?>
<tr><td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b>Total not inc delivery :</b></p></td>
<td valign="top" class="fumbnail2"><p class="upperdash"><b><?=pounds_pence($totalprice+$taxfigure)?></b></p></td></tr></table>
<?
}
}
//$tax $delivery $payment_method
mysql_select_db(antmusic);
if($userid){
//$userdetails

$result7 = mysql_query("SELECT * FROM ggrdetails1 WHERE id=$userid");
$userdetails = mysql_fetch_array($result7);

$newordernumber = "A" . date("d") . date("m") . date("y");
$endordernumber = "ZZ". date("d") . date("m") . date("y");
$stopnow = "no";
while($stopnow == "no" && ($newordernumber <> $endordernumber)){
$result = mysql_query("SELECT * FROM neworder WHERE ordernumber='".$newordernumber."'");
if(mysql_num_rows($result) == 0){
$stopnow = "yes";
}else{
$newordernumber = order_number_generator($newordernumber);
}
}
$todaysdate = date("Y")."-".date("m")."-".date("d");
$emailtopbit = "Order number : ".$newordernumber."\n\n".date("d")."-".date("m")."-".date("Y")."\n\n".stripslashes($userdetails['name'])."\n";
$emailtopbit .= stripslashes($userdetails['address'])."\n".stripslashes($userdetails['town'])."\n".stripslashes($userdetails['county'])."\n".stripslashes($userdetails['country'])."\n".stripslashes($userdetails['postcode'])."\n\n\n".$emailshoppinglist;
$query = "INSERT INTO neworder SET userid=$userid, totalprice='$totalprice',orderdate='$todaysdate',del='$deliveryfigure',vat='$taxfigure'";
$query .= ",ordernumber='$newordernumber', haveseen='n', paymentmethod='credit card',status='ordered', info='Delivery:$delivery\\nTax:$tax\\n$info'";
if(mysql_query($query)){
$orderid = mysql_insert_id();
for($i=0;$i<$ii;$i++){
if(!mysql_query("INSERT INTO partlist1 (orderid, partno, quantity) VALUES (".$orderid.",'".$partnumber[$i]."',".$partquantity[$i].")")){
echo $orderid."-".$partnumber[$i]."-".$partquantity[$i]."<br/>";
}
}

$paypaltotal = $totalprice+$deliveryfigure+$taxfigure;

[1][edited by: GGR_Web at 2:16 pm (utc) on Oct. 24, 2008]

[edited by: eelixduppy at 4:51 pm (utc) on Oct. 24, 2008]
[edit reason] exemplified [/edit]

andrewsmd

12:17 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't debugged anything yet but from a quick glance, you can't put <script> tags within <? tags. Also, when you do php you need to put <?PHP not just <?. You do understand that JavaScript and PHP are two completely different languages correct? I can't help you with JS because I am not a JS programmer. There is a different forum for that. Also, you cant open and close PHP brackets and keep the same if. What I mean is an if else has to be in one <?php if(something) do some code else{ do some other code ?> You can't do <?php if ?> <?php else ?>. Your code needs to be cleaned up a little better before I can help you. You also have various errors in your html and JS. You open a <script type="text/javascript"> tag and then close it right away and then have JS code. You really need to fix this so it is a little more presentable and then I can help. I still don't really understand what you are trying to do but I have cleaned up your code a little bit. Try using this to debug with. It is not working because I don't know what you want it to do but, it is at least in the correct format.
<html>
<body>
<?php
$deliveryfigure = 0;
$emailshoppinglist .= "\tDelivery (".$delivery.")\tTBC\n";
?>

<script type="text/javascript">

<!--Call requested Data from Our mySQL databases and define it as varables-->

<!--google code-->
<!--google tracking begins-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-#*$!#*$!x-1");
pageTracker._trackPageview();
</script>

<!--google ecommcerce tracking begins-->
<script type="text/javascript">
pageTracker._addTrans(
"order-id", // required
"affiliate or store name",
"total",
"tax",
"shipping",
"city",
"state",
"country"
);

pageTracker._addItem(
"order-id", // required
"SKU",
"product name",
"product category",
"unit price", // required
"quantity" //required
);

pageTracker._trackTrans();
</script>
<!--End of Google Tracking-->
<!-- Do not add code here -->

<table>
<tr>
<td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b>Delivery :</b></p>
</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b><?php //=$delivery?></b></p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b>Total not inc delivery :</b></p>
</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b><? //=pounds_pence($totalprice+$taxfigure)?></b></p>
</td>
</tr>
</table>
<table>
<tr>
<td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b>VAT :</b></p>
</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b><?php //=pounds_pence($taxfigure)?></b></p>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b>Full Total :</b></p>
</td>
<td valign="top" class="fumbnail2">
<p class="upperdash"><b><?//=pounds_pence($totalprice+$deliveryfigure+$taxfigure)?></b></p>
</td>
</tr>
</table>

<?php
if($tax == "EC"){
$taxfigure = ceil(($totalprice+$deliveryfigure)*0.175);
$emailshoppinglist .= "\tVAT\t".pounds_pence($taxfigure)."\n";
}//if

else{

$taxfigure = 0;
$emailshoppinglist .= "\tVAT\t£0.00\n";

}//else

if($delivery == "Standard"){

$emailshoppinglist .= "\tFull Total\t".pounds_pence($totalprice+$deliveryfigure+$taxfigure)."\n";

}//if

else{

$emailshoppinglist .= "\tTotal not including delivery\t".pounds_pence($totalprice+$taxfigure)."\n";

}//else

//$tax $delivery $payment_method
mysql_select_db(antmusic);
if($userid){

//$userdetails

$result7 = mysql_query("SELECT * FROM ggrdetails1 WHERE id=$userid");
$userdetails = mysql_fetch_array($result7);

$newordernumber = "A" . date("d") . date("m") . date("y");
$endordernumber = "ZZ". date("d") . date("m") . date("y");
$stopnow = "no";

while($stopnow == "no" && ($newordernumber <> $endordernumber)){

$result = mysql_query("SELECT * FROM neworder WHERE ordernumber='".$newordernumber."'");

if(mysql_num_rows($result) == 0){

$stopnow = "yes";

}//if

else{

$newordernumber = order_number_generator($newordernumber);

}//else

}//while

}//if
$todaysdate = date("Y")."-".date("m")."-".date("d");
$emailtopbit = "Order number : ".$newordernumber."\n\n".date("d")."-".date("m")."-".date("Y")."\n\n".stripslashes($userdetails['name'])."\n";
$emailtopbit .= stripslashes($userdetails['address'])."\n".stripslashes($userdetails['town'])."\n".stripslashes($userdetails['county'])."\n".stripslashes($userdetails['country'])."\n".stripslashes($userdetails['postcode'])."\n\n\n".$emailshoppinglist;
$query = "INSERT INTO neworder SET userid=$userid, totalprice='$totalprice',orderdate='$todaysdate',del='$deliveryfigure',vat='$taxfigure'";
$query .= ",ordernumber='$newordernumber', haveseen='n', paymentmethod='credit card',status='ordered', info='Delivery:$delivery\\nTax:$tax\\n$info'";
if(mysql_query($query)){
$orderid = mysql_insert_id();

for($i=0;$i<$ii;$i++){

if(!mysql_query("INSERT INTO partlist1 (orderid, partno, quantity) VALUES (".$orderid.",'".$partnumber[$i]."',".$partquantity[$i].")")){

echo $orderid."-".$partnumber[$i]."-".$partquantity[$i]."<br/>";

}//if

}//for

$paypaltotal = $totalprice+$deliveryfigure+$taxfigure;
}//if

?>

</body>

</html>

I fixed a couple basic errors with {}s so make sure to correct accordingly.

GGR_Web

2:00 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



I didn't even write this code, I "inhertited" it as part of a website I apparantly maintain.
I've never changed anythin and I can't follow alot of this file.

It is a complete mess - I would use something like wordpress ecommerce or ecart and start over but the company won't let me.

I need to find varables in the second set of code I posted here and define them as something the first set of code will understand as "order-id", "city" ect. I can (probaly locate the varables myself but I do not know how to convert them into java.

I relise that php and javascript are seperate langauges but I believed that it was possible to intergrate them. Is this possible or not?

:(

andrewsmd

3:05 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is possible you just need to separate them. I.E.
<html>
<head><title>some title</title></head>
<script type="text/javascript">
//put all of your JS code here
</script>
<body>
<p> some html stuff</p>
</body>
<?php
//put all of your php code here
//if you want to echo anything within
//your html then add <?php where you
//want it to go
?>
</html>

You probably should create a few simple web pages with html and php before you try to edit this code as it has mysql queries within it.

andrewsmd

3:10 pm on Oct 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try out this code and see if you can understand PHP and JS a little better.
Save this into a file called example1.php

<html>
<?php
//we have to start the session to use session variables
session_start();

?>
<head>

<!-- my css sheet, doctype, and meta tags -->

<link rel= StyleSheet href="index.css" type="text/css">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<meta name = "author" content = "Michael Andrews" />

<meta name = "copyright" content = "September 2008" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Sample page</title>

<script type="text/javascript">

//a simple function that I call on the first checkbox click
function checkBox(){

alert("You checked the box");

}//checkBox

</script>

</head>

<body>

<p class = "titleCenter">Here is your sample page</p>
<br>

<p class = "text">An ordered list</p>
<ol class = "text">
<li>First</li>
<li>Second</li>
<li>Third</li>
</ol>

<p class = "text">An unordered list</p>
<ul class = "text">
<li>First</li>
<li>Second</li>
<li>Third</li>
</ul>
<center class = "text">An example table<br>You can make this border pretty with the css border property.</p></center>
<table align = "center" class = "text" border = "small">
<tr>

<td>This is TR 1 TD 1</td>
<td>This is TR 1 TD 2</td>

</tr>

<tr>

<td>This is TR 2 TD 1</td>
<td>This is TR 2 TD 2</td>

</tr>

</table>
<br><br>
<center class = "text">An example table without a border</p></center>
<table align = "center" class = "text">
<tr>

<td>This is TR 1 TD 1</td>
<td>This is TR 1 TD 2</td>

</tr>

<tr>

<td>This is TR 2 TD 1</td>
<td>This is TR 2 TD 2</td>

</tr>

</table>

<br><br>
<form name = "myForm" method = "post" action = "#submitData">

<p class = "text">
<input type = "checkbox" name = "jsCheck" class = "text" onclick="if(this.checked){checkBox()}">
Here is a checkbox that activates some Javascript.
</p>
<br><br>
<p class = "text">Here is an example dropdown box that I formatted with css.</p>
<p class = "text">Are you a minor?</p>
<select class="dropdown" name = "dropdown">

<option value = "" selected="selected"></option>
<option value = "20">Under 21</option>
<option value = "21">Over 21</option>

</select>

<br><br>

<p class = "text">Here is an example group of radio buttons.</p>

<a name = "submitData" />

<p class = "text">Which sport is the best?</p>
<p class = "text"><input type = "radio" name = "group1" value = "football"> Football</p>
<p class = "text"><input type = "radio" name = "group1" value = "basketball"> Basketball</p>
<p class = "text"><input type = "radio" name = "group1" value = "baseball"> Baseball</p>

<br><br>
<p class = "text"><input type="text" name = "yourName" value = <?php echo($_SESSION['username']); ?>> Enter your name (leave it blank if you want).</p>
<p class = "text"><input type="password" name = "pw" value = <?php echo($_SESSION['password']); ?>> Enter some password.</p>
<br><br>

<center class = "text">

Let's do a math calculation<br><br>
<input type = "text" name = "math1" class = "dropdown" value = <?php echo($_SESSION['math1']); ?>>
<select name = "mathSelection" class = "dropdown">
<option value = "+">+</option>
<option value = "-">-</option>
<option value = "*">*</option>
<option value = "/">/</option>
</select>
<input type = "text" name = "math2" class = "dropdown" value = <?php echo($_SESSION['math2']); ?>>
<br><br>
</center>
<p class = "text"><input type = "submit" value = "Clike Me!" name = "submit"><span class = "spacing">Submit everything you've done
(I used the span class to space this text over some more).</span></p>

</form>
<br><br>
<?php

//I just did this to show you how to add php files
//you could put the php from output.php right here
//and get the same output
//if they clicked the submit button
//we call the php
if(isset($_POST['submit'])){

require_once("output.php");

}
?>

<br><br><br><br><br><br>
<br><br><br><br><br><br>
</body>

</html>

Now save this into a file called index.css

body{

background-image: url(background.jpg);
color: white;
font-family: cursive;

}

.text{
font-size: 25px;

}

.textPad{

padding-left: 2em;
font-size: 20px;
padding-bottom: 1em;

}

.spacing{
padding-left: 3em;
display: inline;
}

.email{
font-size: 12px;
padding-right: 1em;

}

.titleCenter{
font-size: 40px;
padding-bottom: 1em;
text-align: center;
}

.dropdown{

border: groove white;
margin-left: 1em;
background-color: #5E9D9A;
font-family: cursive;
font-size: 20px;
color: white;
display: inline;

}

.list{

padding-left: 3em;
font-size: 20px;

}
.picClass{

padding-left: 4em;

}
a:link{
color: white;
border: white;
padding-bottom: 1em;
display: inline;

}
a:hover{
text-decoration: none;
display: inline;

}
a:visited{

color: white;
border: white;
display: inline;

}

#date{

position: absolute;
padding-left: .5em;
padding-top: .5em;
display: inline;

}

#picture{

text-decoration: none;
position: absolute;
right: .5em;

}

#picture2{

clear: left;
float: right;
display: inline;

}

a.info {

position: relative;
color: white;
font-family: cursive;
border: none;
display: inline;

}

a.info:hover {

text-decoration: none;
background: url("fileDoesNotExist.jpg");
z-index: 6;
display: inline;
}

a.info img {
border: none;
margin-left: 10px; /*adjusting this will control the space betwwen the image and the text */
position: absolute;
left: -9999px; /* hide the "popup" offscreen*/
display: inline;
}

a.info:hover img {
left: auto; /* bring it back on on hover */
top: -16em;
display: inline;
}

quick note on the last one, you need to have an image
saved as background.jpg in the same folder to display a background
image. I used this one I would recommend going here and
downloading this image and saving it as background.jpg

Now save this into a file called output.php

<?php

session_start();

//alright here is how we get that data from the form
//remember in the form tag I use the method post
//so its $_POST if i would have used get
//then it would be $_GET

//this is how you define php variable

//the value of the dropdown box is $_POST['dropdown']
//because I named it dropdown
$dropDownValue = $_POST['dropdown'];

//the value of the radio button
$radio = $_POST['group1'];

//the value of the text box
$userName = $_POST['yourName'];

//set the session variable to maintain the user's input
$_SESSION['username'] = $userName;

//the password
$password = $_POST['pw'];

//set the session variable to maintain the user's input
$_SESSION['password'] = $password;

//the first math input
$first = $_POST['math1'];

//set the session variable to maintain the user's input
$_SESSION['math1'] = $first;

//the second math input
$second = $_POST['math2'];

//set the session variable to maintain the user's input
$_SESSION['math2'] = $second;

//the operator
$operation = $_POST['mathSelection'];

//set the session variable to maintain the user's input
$_SESSION['operation'] = $operation;

//alright now that we have our variables lets do some work
//first lets check to make sure everything is valid
//if they didnt select the minor dropdown box
if($dropDownValue == ""){

//we will tell them and kill the program execution
echo("<p class = 'text'>Select whether or not you are a minor.</p>");
die();

}//if $dropDownValue

//notice i dont have to put an else
//php really doesn't have a whole lot of rules

//check the radio button
if(!(isset($radio))){

//we will tell them and kill the program execution
echo("<p class = 'text'>Select a sport.</p>");
die();

}//if $radio

//notice i used not isset on the second one
//but == "" on the first
//they are NOT the same thing in php

//check the username
if(($userName) == ""){

//we will tell them and kill the program execution
echo("<p class = 'text'>Enter your name.</p>");
die();

}//if $userName

//check the password
if(($password) == ""){

//we will tell them and kill the program execution
echo("<p class = 'text'>Enter a password.</p>");
die();

}//if $password

//check the first and second math inputs
if((!(checkInteger($first))) ¦¦ (!(checkInteger($second))) ){

//we will tell them and kill the program execution
echo("<p class = 'text'>Both boxes must be full and be an integer.</p>");
die();

}//if $userName

//if we are still running then the form was valid lets echo the output

//lets print thier name and password
echo("<p class = 'text'>Welcome $userName, you typed the password $password.");

//if they selected under 20
if($dropDownValue == "20"){

echo("<p class = 'text'>You are not old enough to drink. Stay out of the booze!</p>");

}//if dropdown

//otherwise they are over 21
else{

echo("<p class = 'text'>You are old enough to drink. Stay out of the booze anyways you drunk!</p>");

}//else

//now lets see which sport they chose
if($radio == "football"){

echo("<p class = 'text'>You chose football, nice choice.</p>");

}//if $radio

//if they chose basketball
elseif($radio == "basketball"){

echo("<p class = 'text'>You chose basketball, that's ok with me as long as you don't like the NBA.</p>");

}//elseif $basketball

//else they chose baseball
else{

echo("<p class = 'text'>I hope you mean playing baseball and not watching it.</p>");

}//else

//now let's do the math
//first we need to get the operator they chose then do that computation and
//assign $output as the result

//if they had +
if($operation == "+"){

$output = $first + $second;

}//if $operation

//if they had -
elseif($operation == "-"){

$output = $first - $second;

}//if $operation

//if they had *
elseif($operation == "*"){

$output = $first * $second;

}//if $operation

//if they had /
elseif($operation == "/"){

$output = $first / $second;

}//if $operation

echo("<p class = 'text'>The math operation you created was $first $operation $second which is $output.</p>");

//here is an example function that checks an integer
//since php doesn't define variable types
//if you used the is_int fucntion on the math
//input boxes it would return true
//because "" would equal 0
//and php infers that it is 0 if you
//call a function requiring and integer
//kind of f'd up huh
function checkInteger($var){

//this regular expresion says there must be at least 1 or more
//occurnces of a 0-9 input the \. is escaping the . because
//it means something in regex syntax the * means
//0 or more occurences then 0-9 again 0 or more
$expression = "^([0-9]+)\.*[0-9]*$";

if(ereg($expression,$var)){

return true;

}//if

return false;
}//checkInteger

?>

Run that and play around a bit and see if that makes sense to you.

[edited by: dreamcatcher at 4:39 pm (utc) on Oct. 27, 2008]
[edit reason] No urls please! [/edit]

GGR_Web

4:54 pm on Oct 27, 2008 (gmt 0)

10+ Year Member



"You probably should create a few simple web pages with html and php before you try to edit this code as it has mysql queries within it."

No Kidding!

I've gone and got a php/mysql manual that I'll start working though once I've got the examples on a server - I don't intend to be a n00b forever!

I'll post again when I've had a chance to mess with that code.

andrewsmd

6:18 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well let me know because there are a lot of little tricks to PHP because it is a very loosely structured language and I can save you a lot of time on simple things that you just can't figure out without experience.

GGR_Web

8:45 am on Oct 29, 2008 (gmt 0)

10+ Year Member



I'll keep in touch