473,671 Members | 2,310 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>phpCar t</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_s tyle.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="#EEEEE E">
<td width="10%" class="bottomli ne">&nbsp;</td>
<td width="10%" class="bottomli ne"><strong>Qty </strong></td>
<td width="50%" class="bottomli ne"><strong>Pro duct</strong></td>
<td width="10%" class="bottomli ne"><strong>Pic url</strong></td>
<td width="10%" class="bottomli ne"><strong>Pri ce</strong></td>
<td width="10%" class="bottomli ne"><strong>Lin e 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($_SESSI ON["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("SE LECT * FROM $mysql_tablenam e WHERE id=".$ses_id."" );
$item = mysql_fetch_arr ay($sel_product s);

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

?>
<tr>
<td class="dividing border"><a href="<? echo "phpCart_manage .php?act=del&pi d=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
<td class="dividing border"><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="dividing border"><? echo $item["product"]; ?></td>
<td class="dividing border"><? echo '<img src="'.$item["picurl"].'" width="100" height="100" alt="' . $item["product"] . ' Image"'; ?></td>

<td class="dividing border"><? echo $cur_symbol."". number_format($ item["price"], 2, '.', ''); ?></td>
<td class="dividing border"><? 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>Unkno wn 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=\"UpdateCh g\" type=\"submit\" id=\"UpdateChg\ " value=\"Update\ ">"; } ?></td>
<td><a href="phpCart_s hop.php">Contin ue Shopping</a></td>
<td><strong>Car t 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 2596
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.ph p 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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<td width="306"><a href="phpCart_b asket.php">View Avionics Stack</a></td>
<?
include "functions_cart .php";
db_connect();
$sel_products = mysql_query("SE LECT * FROM $mysql_tablenam e ORDER BY id");
?>
<table width="100%" border="1" cellspacing="0" cellpadding="5" >
<tr><td>&nbsp ;</td>
<td><strong>Pro duct</strong></td>
<td><strong>Pic url</strong></td>
<td><strong>Pri ce</strong></td>
</tr>
<?
while ($item = mysql_fetch_arr ay($sel_product s)) {
echo "<tr>";
echo "<td><a href=phpCart_ma nage.php?act=ad d&pid=".$item["id"].">Add</a></td>";
echo "<td>".$ite m["product"]."</td>";
echo '<td><img src="'.$item["picurl"].'" width="auto" height="auto" alt="' . $item["product"] . ' Image"></td>';
echo "<td>".$ite m["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>phpCar t</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_s tyle.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="#EEEEE E">
<td width="10%" class="bottomli ne">&nbsp;</td>
<td width="5%" class="bottomli ne"><strong>Qty </strong></td>
<td width="5%" class="bottomli ne"><strong>LCo de</strong></td>
<td width="50%" class="bottomli ne"><strong>Pro duct</strong></td>
<td width="10%" class="bottomli ne"><strong>Ima ge</strong></td>
<td width="10%" class="bottomli ne"><strong>Pri ce</strong></td>
<td width="10%" class="bottomli ne"><strong>Lin e 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($_SESSI ON["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("SE LECT * FROM $mysql_tablenam e WHERE id=".$ses_id."" );
$item = mysql_fetch_arr ay($sel_product s);

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

?>
<tr>
<td class="dividing border"><a href="<? echo "phpCart_manage .php?act=del&pi d=".$ses_id; ?>"><img src="img/icon_del.gif" width="13" height="13" border="0"></a></td>
<td class="dividing border"><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="dividing border"><? echo $item["code"]; ?></td>
<td class="dividing border"><? echo $item["product"]; ?></td>
<td class="dividing border"><? echo '<img src="'.$item["picurl"].'" width="auto" height="auto" alt="' . $item["product"] . ' Image"'; ?></td>

<td class="dividing border"><? echo $cur_symbol."". number_format($ item["price"], 2, '.', ''); ?></td>
<td class="dividing border"><? 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>Unkno wn 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=\"UpdateCh g\" type=\"submit\" id=\"UpdateChg\ " value=\"Update\ ">"; } ?></td>
<td><a href="phpCart_s hop.php">Add More Avionics</a></td>
<td><strong>Sta ck 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_tablenam e = "phpcart_produc ts";

$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,"s tring");

// 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_car t($id,$quantity ) {

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

// call database connect function
db_connect();
// get product id from database
global $mysql_tablenam e;
$sel_products = mysql_query("SE LECT * FROM $mysql_tablenam e WHERE id=".$id."");
$item = mysql_fetch_arr ay($sel_product s);
// 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_regener ate_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($_COOKI E['SESSSEC'])) {
$valid = FALSE;
// probable attempt at Session Fixation, you should probably log this
} elseif (!isset($_SESSI ON["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_tablenam e;
$sel_products = mysql_query("SE LECT * FROM $mysql_tablenam e WHERE id=".$id."");
$item = mysql_fetch_arr ay($sel_product s);

session_start() ;

// remove item from cart
session_regener ate_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>phpCar t</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="phpCart_s tyle.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($ba dsymbols,"", $_POST["newquan"][$i]);

if (is_numeric($_P OST["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_exis ts($_POST["eid"][$i], $_SESSION["cart"])) {

add_item_to_car t($_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($_S ESSION["cart"]);
if (!isset($_SESSI ON["cart"])) {

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

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

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

} else {

// add any other items after first item
add_item_to_car t($_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
3956
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 screen. I grabbed this code from the net hoping that I could tweak it for my needs. I'm using MySQL, PHP and IIS and they all are running fine. As the code is, it will display the form, but it won't display my result(s). Any suggestions? Cheers,
2
3426
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 new values are updated in all corresponding tables (the function of the pages in question). However, on the page that does the DB update, I also want to do some checks on the data before performing the update. Now, the problem that I am...
13
2727
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 the iSeries Client Access Driver ver 10.00.04.00 to connect to the database. The problem is that executing the exact same SQL select statement more than twice int a row stops produces results. The first two instances will always produce the...
8
3698
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 to return the results as they query executes rather than wait for the whole query to execute. Basically, I want to get the results as they are prepared by the database. Any way to do this?
2
3319
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 which sends an email reminder to each customer in the database, that has outstanding orders. This email reminder should have the results of the query regarding their account. The table structure are as follows.
1
1168
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 lines at a time,) add that information to the body of an email and automatically send it. Any idea of how to do the email piece of this? I'm assuming it will be via SMTP.
36
3031
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 have set up a Query to show only records that meet a certain criteria...therefore excluding all of the records that do not meet this criteria (just for the record the criteria is any record within my database that falls within two months of its "Due...
1
6551
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 specifies for each record... Essentially this is a make shift Ordering Tool and I want to be able to notify the receiver of the order and its specifics. q_Order_Detail_4email consists of ,,, and Example: Hello@mail.com,956,Modem,1000,xyz123...
9
3019
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 except that I can't get the value of holiday_ID included as a querystring. As a test I can insert a value after the ?id= and this is passed as a querystring. I am sure it's just the syntax that I am having problem with
0
8388
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8907
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8593
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8663
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5687
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4396
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2804
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 we have to send another system
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.