Download - 71057737 Carrito en Php
-
7/28/2019 71057737 Carrito en Php
1/30
Hola mi primer POST que tratara de comohacerun carrito decompras, antesque nada yo no lo hise lo encontre en internet por que lo posteo? soyestudiante y tenia muchicimos proyectos que entregar en un semestre y unmaestro se le ocurrio que nuestro proyecto final seria un carrito de compras y
tenia que estar hecho en DREAMWEAVER, MYSQL, y PHP, bueno estabademaciado atareado para hacer este proyecto asi que me di a la tarea debuscarlo y dicen que el que busca encuentra y HOY SE LOS PASO A LACOMUNIDAD DE TARINGA Y LOS QUE SON ESTUDIANTES Y NO SABEN PORDONDE INICIAR.
Antes de poder iniciar tenemos que tener instalado el Appserver en nuestracomputadora
1.- Vamos a crear una base de datos en MySql y abriremos Command
Line Client que se encuentra en INICIO-TODOS LOS PROGRAMAS y
pondremos el siguiente codigo.
create data base Sql18226_1;use Sql18226_1;
create table customers(customerid int unsigned not null auto_increment primary key,name char(40) not null,address char(40) not null,citychar(20) not null,state char(20),zip char(10),country char(20) not null);
create table orders(orderid int unsigned not null auto_increment primary key,customerid int unsigned not null,amount float(6,2),date date not null,
order_status char(10),
http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=69ab1969ef92df62&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=69ab1969ef92df62&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=69ab1969ef92df62&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=f31ee604cfedd99b&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=f31ee604cfedd99b&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=f31ee604cfedd99b&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=3da0e9f745e75306&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=3da0e9f745e75306&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=dc0fee868195e340&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=dc0fee868195e340&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=dc0fee868195e340&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=3da0e9f745e75306&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=f31ee604cfedd99b&fi=df4bbc30ac6873b8http://ads.us.e-planning.net/ei/3/805f/57caa0b06e6fa9f9?rnd=0.4938054574766964&pb=69ab1969ef92df62&fi=df4bbc30ac6873b8 -
7/28/2019 71057737 Carrito en Php
2/30
ship_name char(40) not null,ship_address char(40) not null,ship_city char(20) not null,ship_state char(20),
ship_zip char(10),ship_country char(20) not null);
create table books(isbn char(13) not null primary key,author char(30),
title char(60),catid int unsigned,price float(4,2) not null,description varchar(255));
create table categories(
catid int unsigned not null auto_increment primary key,catname char(40) not null);
create table order_items(orderid int unsigned not null,isbn char(13) not null,item_price float(4,2) not null,quantity tinyint unsigned not null,primary key (orderid, isbn));
create table admin(username char(16) not null primary key,password char(16) not null
);
-
7/28/2019 71057737 Carrito en Php
3/30
2.- Luego pondremos en el Mismo Command Line Cliente el siguiente
codigo.USE Sql18226_1;
INSERT INTO books VALUES ('0672317842','Luke Welling and LauraThomson','PHP and MySQL Web Development',1,49.99,'PHP & MySQL WebDevelopment teaches the reader to develop dynamic, secure e-commerce websites. You will learn to integrate and implement these technologies by followingreal-world examples and working sample projects.');INSERT INTO books VALUES ('0672318040','Matt Zandstra','Sams TeachYourself PHP4 in 24 Hours',1,24.99,'Consisting of 24 one-hour lessons, SamsTeach Yourself PHP4 in 24 Hours is divided into five sections that guide you
through the language from the basics to the advanced functions.');INSERT INTO books VALUES ('0672319241','Sterling Hughes and AndreiZmi','PHP Developer's Cookbook',1,39.99,'Provides a complete, solutions-oriented guide to the challenges most often faced by PHP developersrnWrittenspecifically for experienced Web developers, the book offers real-worldsolutions to real-world needsrn');
INSERT INTO categories VALUES (1,'Internet');
INSERT INTO categories VALUES (2,'Self-help');INSERT INTO categories VALUES (5,'Fiction');INSERT INTO categories VALUES (4,'Gardening');
INSERT INTO admin VALUES ('admin', password('admin'));
3.- Empesaremos abriendo Dreamweaver y creando un Nuevo Sitio en
Menu-Sitio-NuevoSitio.
recuerda que tienes que tener previamente una carpetac:/appserver/www/(nombre de tu carpeta)
4.- Empesaremos creando un archivo PHP se llamara Index.php y le
agregaremos este codigo.
-
7/28/2019 71057737 Carrito en Php
4/30
session_start();do_html_header("Bienvenido a la Tienda de Cocinando con JADA";
echo "
Selecciona Libros:
";$cat_array = get_categories();
display_categories($cat_array);
if(session_is_registered("admin_user"){display_button("admin.php", "admin-menu", "Admin Menu";
}
do_html_footer();?>
5.- Ahora vamos a crear el siguiente archivo que se llamara
order_fns.php y tendra el siguiente codigo.
-
7/28/2019 71057737 Carrito en Php
5/30
$ship_name = $name;$ship_address = $address;$ship_city = $city;$ship_state = $state;
$ship_zip = $zip;$ship_country = $country;}
$conn = db_connect();
$query = "select customerid from customers wherename = '$name' and address = '$address'
and city = '$city' and state = '$state'and zip = '$zip' and country = '$country'";$result = mysql_query($query);if(mysql_numrows($result)>0){$customer_id = mysql_result($result, 0, "customerid";}else
{$query = "insert into customers values('', '$name','$address','$city','$state','$zip','$country')";$result = mysql_query($query);if (!$result)return false;}$query = "select customerid from customers wherename = '$name' and address = '$address'and city = '$city' and state = '$state'and zip = '$zip' and country = '$country'";$result = mysql_query($query);if(mysql_numrows($result)>0)$customerid = mysql_result($result, 0, "customerid";elsereturn false;$date = date("Y-m-d";
$query = "insert into orders values
-
7/28/2019 71057737 Carrito en Php
6/30
('', $customerid, $total_price, '$date', 'PARTIAL', '$ship_name','$ship_address','$ship_city','$ship_state','$ship_zip','$ship_country')";$result = mysql_query($query);
if (!$result)return false;
$query = "select orderid from orders wherecustomerid = $customerid andamount > $total_price-.001 andamount < $total_price+.001 anddate = '$date' and
order_status = 'PARTIAL' andship_name = '$ship_name' andship_address = '$ship_address' andship_city = '$ship_city' andship_state = '$ship_state' andship_zip = '$ship_zip' andship_country = '$ship_country'";$result = mysql_query($query);
if(mysql_numrows($result)>0)$orderid = mysql_result($result, 0, "orderid";elsereturn false;
foreach($cart as $isbn => $quantity){$detail = get_book_details($isbn);$query = "delete from order_items whereorderid = '$orderid' and isbn = '$isbn'";$result = mysql_query($query);$query = "insert into order_items values('$orderid', '$isbn', ".$detail["price"].", $quantity)";$result = mysql_query($query);if(!$result)return false;
}
-
7/28/2019 71057737 Carrito en Php
7/30
return $orderid;}
?>
6.-Vamos a crear otro archivo se llamara output_fns.php que sera
nuestro archivo mas extenso.
h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red;margin = 6px }body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }hr { color: #FF0000; width=70%; text-align=center}a { color: #000000 }
-
7/28/2019 71057737 Carrito en Php
8/30
-
7/28/2019 71057737 Carrito en Php
9/30
function do_html_heading($heading){// print heading
?>
-
7/28/2019 71057737 Carrito en Php
10/30
//display all books in the array passed inif (!is_array($book_array)){echo "
No books currently available in this category
";}else{//create tableecho "";
//create a table row for each bookforeach ($book_array as $row)
{$url = "show_book.php?isbn=".($row["isbn"]);echo "";if (@file_exists("images/".$row["isbn"].".jpg"){$title = "";do_html_url($url, $title);}
else{echo "";}echo "";$title = $row["title"]." de ".$row["author"];do_html_url($url, $title);echo "";}echo "";}echo "";}
function display_book_details($book){// display all details about this book
if (is_array($book))
-
7/28/2019 71057737 Carrito en Php
11/30
{echo "";//display the picture if there is oneif (@file_exists("images/".($book["isbn"]).".jpg")
{$size = GetImageSize("images/".$book["isbn"].".jpg";if($size[0]>0 && $size[1]>0)echo "";}echo "";echo "Autor: ";
echo $book["author"];echo "ISBN: ";echo $book["isbn"];echo "Nuestro Precio: ";echo number_format($book["price"], 2);echo "Descripcin: ";echo $book["description"];echo "";
}elseecho "Los detalles de este libro no pueden ser mostrados en este momento.";echo "";}
function display_checkout_form(){//display the form that asks for name and address?>
Su informacinNombre -
7/28/2019 71057737 Carrito en Php
12/30
event.keyCode < 0) || (event.keyCode > 0 && event.keyCode < 65) ||(event.keyCode > 0 && event.keyCode < 32)) event.returnValue =false;"maxlength = 40 size = 40>
function clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""}Direccinfunction clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""
}Ciudad/Suburbiofunction clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""}Estado/Provincia
-
7/28/2019 71057737 Carrito en Php
13/30
onFocus="clearText(this)" onKeypress="if ((event.keyCode > 0 &&event.keyCode < 0) || (event.keyCode > 0 && event.keyCode < 65) ||(event.keyCode > 0 && event.keyCode < 32)) event.returnValue =false;"maxlength = 20 size = 40>
function clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""}Cdigo Postal o Cdigo Zip
function clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""}
Pasfunction clearText (thefield){if(thefield.defaultValue==thefield.value)thefield.value=""}Direccin de envo (dejar en blanco sies el de arriba)Nombre
-
7/28/2019 71057737 Carrito en Php
14/30
40>Direccin
Ciudad/Suburbio
Estado/ProvinciaCdigo Postal o Cdigo ZipPasPor favor pulsar compar para confirmar su compra,o Continuar comprando para aadir o eliminar artculos
-
7/28/2019 71057737 Carrito en Php
15/30
function display_shipping($shipping){// display table row with shipping cost and total price including shipping
global $total_price;?>Envo TOTAL INCLUIDO ENVO$
Detalles Tarjeta CrditoTipoVISAMasterCardAmericanExpressNmeroCdig AMEX code (si se requiere) -
7/28/2019 71057737 Carrito en Php
16/30
4>Fecha Expiracin
Mes 010203040506070809101112ao 0001020304050607080910
Nombre en Tarjeta
-
7/28/2019 71057737 Carrito en Php
17/30
global $total_price;
echo "
ItemPriceQuantityTotal";
//display each item as a table rowforeach ($cart as $isbn => $qty){$book = get_book_details($isbn);
echo "";if($images ==true){echo "";if (file_exists("images/$isbn.jpg"){$size = GetImageSize("images/".$isbn.".jpg";if($size[0]>0 && $size[1]>0)
{echo "";}}elseecho "";echo "";}echo "";echo "".$book["title"]." de".$book["author"];echo "$".number_format($book["price"], 2);echo "";// if we allow changes, quantities are in text boxesif ($change == true)echo "";
else
-
7/28/2019 71057737 Carrito en Php
18/30
echo $qty;echo "$".number_format($book["price"]*$qty,2)."n";}
// display total rowecho "$items$".number_format($total_price, 2).
"";// display save change buttonif($change == true){echo "
";}echo "";}
function display_login_form(){// dispaly form asking for name and password?>
Nombre Usuario:
-
7/28/2019 71057737 Carrito en Php
19/30
Contrasea:
Ir al sitio principal
Aadir una nueva categora
Aadir un nuevo libro
Cambiar la contrasea deAdmin
-
7/28/2019 71057737 Carrito en Php
20/30
7.- Crearemos otro archivo este archivo se llamara process.php
-
7/28/2019 71057737 Carrito en Php
21/30
8.- Crearemos un archivo que se llamara purchase.php
-
7/28/2019 71057737 Carrito en Php
22/30
-
7/28/2019 71057737 Carrito en Php
23/30
{if(!session_is_registered("cart"){$cart = array();
session_register("cart";$items = 0;session_register("items";$total_price = "0.00";session_register("total_price";}if($cart[$new])$cart[$new]++;
else$cart[$new] = 1;$total_price = calculate_price($cart);$items = calculate_items($cart);
}if($save){
foreach ($cart as $isbn => $qty){if($$isbn=="0"unset($cart[$isbn]);else$cart[$isbn] = $$isbn;}$total_price = calculate_price($cart);$items = calculate_items($cart);}
do_html_header("Tu carro de compra" ;
if($cart&&array_count_values($cart))display_cart($cart);else{
echo "
No hay artculos en tu carro";
-
7/28/2019 71057737 Carrito en Php
24/30
echo "";}$target = "index.php";
if($new){$details = get_book_details($new);if($details["catid"])$target = "show_cat.php?catid=".$details["catid"];}display_button($target, "continue-shopping", "Continue Shopping";$path = $PHP_SELF;
$path = str_replace("show_cart.php", "", $path);display_button("http://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout";do_html_footer();?>
10.- creamos otro archivo sera show_cat.php que es completamente
diferente al de show_cart.php
-
7/28/2019 71057737 Carrito en Php
25/30
display_button("edit_category_form.php?catid=$catid", "edit-category", "EditCategory";}else
display_button("index.php", "continue-shopping", "Continue Shopping";
do_html_footer();?>
11.- creamos el siguiente archivo book_fns.php
-
7/28/2019 71057737 Carrito en Php
26/30
where catid = $catid";$result = @mysql_query($query);if (!$result)return false;
$num_cats = @mysql_num_rows($result);if ($num_cats ==0)return false;$result = mysql_result($result, 0, "catname";return $result;}
function get_books($catid){if (!$catid || $catid==""return false;
$conn = db_connect();$query = "select * from books where catid='$catid'";$result = @mysql_query($query);
if (!$result)return false;$num_books = @mysql_num_rows($result);if ($num_books ==0)return false;$result = db_result_to_array($result);return $result;}
function get_book_details($isbn){if (!$isbn || $isbn==""return false;
$conn = db_connect();$query = "select * from books where isbn='$isbn'";$result = @mysql_query($query);
if (!$result)
-
7/28/2019 71057737 Carrito en Php
27/30
return false;$result = @mysql_fetch_array($result);return $result;}
function calculate_price($cart){$price = 0.0;if(is_array($cart)){$conn = db_connect();foreach($cart as $isbn => $qty)
{$query = "select price from books where isbn='$isbn'";$result = mysql_query($query);if ($result){$item_price = mysql_result($result, 0, "price";$price +=$item_price*$qty;}
}}return $price;}
function calculate_items($cart){$items = 0;if(is_array($cart)){foreach($cart as $isbn => $qty){$items += $qty;}}return $items;}
-
7/28/2019 71057737 Carrito en Php
28/30
?>
12.- creamos otro archivo y sera book_sc_fns.php con el siguiente
codigo
-
7/28/2019 71057737 Carrito en Php
29/30
14.- creamos el siguiente archivo data_valid_fns.php
-
7/28/2019 71057737 Carrito en Php
30/30
return $result;}
function db_result_to_array($result)
{$res_array = array();
for ($count=0; $row = @mysql_fetch_array($result); $count++)$res_array[$count] = $row;
return $res_array;}
?>
PARA PODER CORRER LA APLICACION TENDREMOS QUE IR A EL EXPLORADORY PONDREMOS LA SIGUIENTE DIRECCION QUE SERAhttp://localhost/tienda_online/index.php
localhost es el servidor
tienda_online es el nombre de la carpeta que creamos en www dentro deappseverindex.php es el primer formulario PHP que creamos.
DISCULPEN PERO NO SE COMO METER IMAGENES PERO SI NECESITANAYUDA ESCRIBAN SEGURAMENTE LES PUEDO AYUDAR.
JIMMYMIENTRAS EL CONOCIMIENTO LO COMPARTAS CON TODOS,
MAS APRENDEREMOS CERO EGOISMOJIMMY