473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

email query results

4 New Member
I'm pulling hair out of my bald head trying to figure out how to set up a form box within this fairly simple PHP script, (this script works fine), that allows a user to enter their email address, and when they hit the submit button it send them a list of the query results as well as me. The only item from the query results that can be omitted from the email would be the images. Any help would be very gratefully appreciated. Below is the script.

[PHP]<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
</head>

<body>
<form name="update" method="post" action="phpCart_manage.php">
<table width="50%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#EEEEEE">
<td width="10%" class="bottomline">&nbsp;</td>
<td width="10%" class="bottomline"><strong>Qty</strong></td>
<td width="50%" class="bottomline"><strong>Product</strong></td>
<td width="10%" class="bottomline"><strong>Picurl</strong></td>
<td width="10%" class="bottomline"><strong>Price</strong></td>
<td width="10%" class="bottomline"><strong>Line Total </strong></td>
</tr>
<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {

foreach ($_SESSION["cart"] as $key => $session_data) {

list($ses_id, $ses_quan) = $session_data;

// call database connect function
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
$item = mysql_fetch_array($sel_products);

$totalvalue = $totalvalue + ($item["price"]*$ses_quan);
$subtotal = ($item["price"]*$ses_quan);

?>
<tr>
<td class="dividingborder"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
<td class="dividingborder"><input name="newquan[]" type="text" id="newquan[]4" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
<td class="dividingborder"><? echo $item["product"]; ?></td>
<td class="dividingborder"><? echo '<img src="'.$item["picurl"].'" width="100" height="100" alt="' . $item["product"] . ' Image"'; ?></td>

<td class="dividingborder"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
<td class="dividingborder"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
</tr>
<?
} // end foreach loop

} elseif ($_SESSION["cart"] == NULL) {

echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";

} else {

echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
?>
<tr>
<td> <img src="img/icon_del.gif" width="13" height="13"> - delete</td>
<td><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
<td><a href="phpCart_shop.php">Continue Shopping</a></td>
<td><strong>Cart Total</strong></td>
<td><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
</tr>
</table>
</form>
</body>
</html>
<?
ob_end_flush();
?>[/PHP]
Oct 30 '06 #1
4 2570
ronverdonk
4,258 Recognized Expert Specialist
I am trying to find a 'checkout' handling routine, but I couldn't find one. I also tried to find a name, address, zip, etc. prompt. So the user, somewhere in the form, because it is not clear what the user enters in the form (where do you prompt for his name, address, etc?) enters his email adress. Then at what point do you want the email to be send?

Ronald :cool:
Oct 31 '06 #2
danxavier
4 New Member
There's no checkout routine code written. It just display the results. The script before this allows the user to select for the cart, and when update is submitted by the user it passes the cart items to the script written above (phpCart_basket.php). Thanks
Oct 31 '06 #3
ronverdonk
4,258 Recognized Expert Specialist
Can you influence the form on which the order is actually made, i.e. the form that launches this form. If so, can the order form also request an email address from the user, so it can be transferred either in a POST or GET array or via the $_SESSION array? Or do you have to prompt the user from this form??

Let me know and we'll work out the format and content of the email to send.

Ronald :cool:
Oct 31 '06 #4
danxavier
4 New Member
Thanks so much for helping out. I'm trying to set this for a non-profit I volunteer with. The program is based on four scripts:

phpCart_shop.php is where you select your items

phpCart_basket.php displays the results

functions_cart.php is the middle man

phpCart_manage is a middle man but I'm not sure what it does?

Here is the code for each one, in order

[PHP]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<td width="306"><a href="phpCart_basket.php">View Avionics Stack</a></td>
<?
include "functions_cart.php";
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename ORDER BY id");
?>
<table width="100%" border="1" cellspacing="0" cellpadding="5">
<tr><td>&nbsp;</td>
<td><strong>Product</strong></td>
<td><strong>Picurl</strong></td>
<td><strong>Price</strong></td>
</tr>
<?
while ($item = mysql_fetch_array($sel_products)) {
echo "<tr>";
echo "<td><a href=phpCart_manage.php?act=add&pid=".$item["id"].">Add</a></td>";
echo "<td>".$item["product"]."</td>";
echo '<td><img src="'.$item["picurl"].'" width="auto" height="auto" alt="' . $item["product"] . ' Image"></td>';
echo "<td>".$item["price"]."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>[/PHP]

[PHP]<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">

</head>

<body>
<form name="update" method="post" action="phpCart_manage.php">
<table width="50%" border="0" cellspacing="10" cellpadding="0">
<tr bgcolor="#EEEEEE">
<td width="10%" class="bottomline">&nbsp;</td>
<td width="5%" class="bottomline"><strong>Qty</strong></td>
<td width="5%" class="bottomline"><strong>LCode</strong></td>
<td width="50%" class="bottomline"><strong>Product</strong></td>
<td width="10%" class="bottomline"><strong>Image</strong></td>
<td width="10%" class="bottomline"><strong>Price</strong></td>
<td width="10%" class="bottomline"><strong>Line Total </strong></td>
</tr>
<?
include "functions_cart.php";
$totalvalue = 0;

session_start();
// If no sessions has been started $_SESSION["cart"] equals null, thus showing the message no items.
if (!isset($_SESSION["cart"])) {
$_SESSION["cart"] = NULL;
}

if (validate() == TRUE && $_SESSION["cart"] != NULL) {

foreach ($_SESSION["cart"] as $key => $session_data) {

list($ses_id, $ses_quan) = $session_data;

// call database connect function
db_connect();
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$ses_id."");
$item = mysql_fetch_array($sel_products);

$totalvalue = $totalvalue + ($item["price"]*$ses_quan);
$subtotal = ($item["price"]*$ses_quan);

?>
<tr>
<td class="dividingborder"><a href="<? echo "phpCart_manage.php?act=del&pid=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
<td class="dividingborder"><input name="newquan[]" type="text" id="newquan[]4" value="<? echo $ses_quan; ?>" size="5" maxlength="4">
<input name="eid[]" type="hidden" id="eid[]" value="<? echo $ses_id; ?>"></td>
<td class="dividingborder"><? echo $item["code"]; ?></td>
<td class="dividingborder"><? echo $item["product"]; ?></td>
<td class="dividingborder"><? echo '<img src="'.$item["picurl"].'" width="auto" height="auto" alt="' . $item["product"] . ' Image"'; ?></td>

<td class="dividingborder"><? echo $cur_symbol."".number_format($item["price"], 2, '.', ''); ?></td>
<td class="dividingborder"><? echo $cur_symbol."".number_format($subtotal, 2, '.', ''); ?></td>
</tr>
<?
} // end foreach loop

} elseif ($_SESSION["cart"] == NULL) {

echo "<td colspan=\"5\"><center><p>Your basket is currently empty.</p></center></td>";

} else {

echo "<td colspan=\"5\"><center><p>Unknown Error.</p></center></td>";

}
?>
<tr>
<td> <img src="img/icon_del.gif" width="13" height="13"> - delete</td>
<td><? if ($_SESSION["cart"] != NULL) { echo "<input name=\"UpdateChg\" type=\"submit\" id=\"UpdateChg\" value=\"Update\">"; } ?></td>
<td><a href="phpCart_shop.php">Add More Avionics</a></td>
<td><strong>Stack Total</strong></td>
<td><? echo $cur_symbol."".number_format($totalvalue, 2, '.', ''); ?></td>
</tr>
</table>
</form>

</body>
</html>
<?
ob_end_flush();
?>

[/PHP]

[PHP]<?
$mysql_server = "localhost";
$mysql_username = "flying";
$mysql_pwd = "copole";
$mysql_dbname = "flying_phpcart";
$mysql_tablename = "phpcart_products";

$cur_symbol = "$";

// database connect function
function db_connect () {

global $mysql_server, $mysql_username, $mysql_pwd, $mysql_dbname;

$db = mysql_connect($mysql_server, $mysql_username, $mysql_pwd, false, 128) or die("Problem connecting");
mysql_select_db($mysql_dbname,$db) or die("Problem selecting database");

}


// generate random string for cookie and session
function setstp () {

settype($str,"string");

// generate random number
for ($i=0;$i<20;$i++) {

$str .= chr (rand (1, 255));

}

// encode string to 40 characters.
$sha = sha1 ($str);
// set cookie with value and set session with the same value.
setcookie ("SESSSEC", $sha, NULL);
$_SESSION["CookieChk"]['SESSSEC'] = $sha;

}


// add item to cart
function add_item_to_cart($id,$quantity) {

// set cookie and store value in session
setstp();

// call database connect function
db_connect();
// get product id from database
global $mysql_tablename;
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$id."");
$item = mysql_fetch_array($sel_products);
// returns the number of rows in a result, if 1 item exists if 0 item doesn't exists.
$num_rows = mysql_num_rows($sel_products);

// if item exists then add item to cart
if ($num_rows >= 1) {

session_regenerate_id(TRUE);

$_SESSION["cart"][$id][0] = $item["id"];
$_SESSION["cart"][$id][1] = $quantity;

header ("location:".$_SERVER['HTTP_REFERER']);

}
}


// check cookie and session and then show cart
function validate() {

if (!isset($_COOKIE['SESSSEC'])) {
$valid = FALSE;
// probable attempt at Session Fixation, you should probably log this
} elseif (!isset($_SESSION["CookieChk"]['SESSSEC'])) {
$valid = FALSE;
// umm, this shouldn't occur, but yeah, do whatever you want, maybe log an error or something, probably not needed except to notice bugs in your app....
} elseif ($_COOKIE["SESSSEC"] == $_SESSION["CookieChk"]['SESSSEC']) {
$valid = TRUE;
setstp();
} else {
$valid = FALSE;
// very Proably attempt at session hijacking, because while both items exist they don't match, definately log this
}
return $valid;
}


// delete item from cart
function del_item($id) {

// call database connect function
db_connect();
global $mysql_tablename;
$sel_products = mysql_query("SELECT * FROM $mysql_tablename WHERE id=".$id."");
$item = mysql_fetch_array($sel_products);

session_start();

// remove item from cart
session_regenerate_id();
unset($_SESSION["cart"][$item["id"]]);

header ("location:".$_SERVER['HTTP_REFERER']);

}


?>
[/PHP]
[PHP]<?
ob_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>phpCart</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_style.css" rel="stylesheet" type="text/css">
<?
// UPDATE BASKET QUANTITY
if (isset($_POST["UpdateChg"])) {

session_start();
include "functions_cart.php";

$i = 0;
$size = count($_POST["eid"]);

for ($i = 0; $i <= $size-1; $i++) {

// call remove bad characters function
$badsymbols = array(" ","-","+","*","/",".");
$_POST["newquan"][$i] = str_replace($badsymbols,"", $_POST["newquan"][$i]);

if (is_numeric($_POST["newquan"][$i])) {

// if any quantity's equal 0 then remove from cart
if ($_POST["newquan"][$i] == 0) {
unset($_SESSION["cart"][$_POST["eid"][$i]]);
}

// update quantity in cart.
if (array_key_exists($_POST["eid"][$i], $_SESSION["cart"])) {

add_item_to_cart($_POST["eid"][$i], $_POST["newquan"][$i]);

}

} // END IF NUMERIC

}

header ("location:".$_SERVER['HTTP_REFERER']);

} // END BASKET QUANTITY

// TEXT LINKS
if (isset($_GET["act"])) {

// ADD ITEM!
if ($_GET["act"] == "add") {

session_start();
include "functions_cart.php";
//unserialize($_SESSION["cart"]);
if (!isset($_SESSION["cart"])) {

// add first item
add_item_to_cart($_GET["pid"],1);

} else if (array_key_exists($_GET["pid"], $_SESSION["cart"])) {

// add 1 to quantity if item in cart already
add_item_to_cart($_GET["pid"],++$_SESSION["cart"][$_GET["pid"]][1]);

} else {

// add any other items after first item
add_item_to_cart($_GET["pid"],1);

}

}


// DELETE ITEM!
if ($_GET["act"] == "del") {

include "functions_cart.php";
del_item($_GET["pid"]);

}

} // END ISSET
?>
</body>
</html>
<?
ob_end_flush();
?>
[/PHP]
Nov 2 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3950
by: Mike Cocker | last post by:
Hello, I'm quite weak at PHP, so I was hoping to get some help understanding the below code. First off, I'm trying to create a "query form" that will allow me to display the results on my...
2
3413
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
13
2718
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
8
3693
by: san | last post by:
Hi, I wanted to know if this is possible and if so, how do I do it. Say, I have a query "SELECT * FROM Table WHERE Column="some_value". This executes on a very large data set and I would like...
2
3306
by: serendipity | last post by:
Hi, I'm not sure if this is possible as i've googled everywhere, but i have a select query that returns a customer record with their associated sales orders. I would like to automate a process...
1
1164
by: Ken Barz | last post by:
Hi, I'm working on a program that will periodically run a query on a SQL database. What I would like it to do is to automatically take the results of that query (should be only a couple of...
36
2990
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
1
6536
by: sxwend | last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
9
2999
by: paulmitchell507 | last post by:
I have a file called email2.asp which I am using to mail data obtained from a SQL query. I would like to pass the holiday_ID value in the querystring attached to the end of the URL. It all works...
0
7260
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
7160
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
7525
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
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.