Forum Moderators: coopster
<!--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]
<?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.
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]
<?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.
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.
<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]
<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>
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.
<?
<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 -->
?>
<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(in_array("no",$lastliststatus)){ <tr><td colspan="2"> </td> $result7 = mysql_query("SELECT * FROM ggrdetails1 WHERE id=$userid"); $newordernumber = "A" . date("d") . date("m") . date("y"); $paypaltotal = $totalprice+$deliveryfigure+$taxfigure; [1][edited by: GGR_Web at 2:16 pm (utc) on Oct. 24, 2008]
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'];
}
}
$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>
<?
}
}
}
?>
<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"> </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"> </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"> </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"> </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"> </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
$userdetails = mysql_fetch_array($result7);
$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/>";
}
}
[edited by: eelixduppy at 4:51 pm (utc) on Oct. 24, 2008]
[edit reason] exemplified [/edit]
<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"> </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"> </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"> </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"> </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.
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?
:(
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.
<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]
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.