Sei sulla pagina 1di 30

Hola mi primer POST que tratara de como hacer un carrito de compras, antes que nada yo no lo hise lo encontre en internet

por que lo posteo? soy estudiante y tenia muchicimos proyectos que entregar en un semestre y un maestro se le ocurrio que nuestro proyecto final seria un carrito de compras y tenia que estar hecho en DREAMWEAVER, MYSQL, y PHP, bueno estaba demaciado atareado para hacer este proyecto asi que me di a la tarea de buscarlo y dicen que el que busca encuentra y HOY SE LOS PASO A LA COMUNIDAD DE TARINGA Y LOS QUE SON ESTUDIANTES Y NO SABEN POR DONDE INICIAR. Antes de poder iniciar tenemos que tener instalado el Appserver en nuestra computadora 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, city char(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),

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 );

2.- Luego pondremos en el Mismo Command Line Cliente el siguiente codigo. USE Sql18226_1; INSERT INTO books VALUES ('0672317842','Luke Welling and Laura Thomson','PHP and MySQL Web Development',1,49.99,'PHP & MySQL Web Development teaches the reader to develop dynamic, secure e-commerce web sites. You will learn to integrate and implement these technologies by following real-world examples and working sample projects.'); INSERT INTO books VALUES ('0672318040','Matt Zandstra','Sams Teach Yourself PHP4 in 24 Hours',1,24.99,'Consisting of 24 one-hour lessons, Sams Teach 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 Andrei Zmi','PHP Developer's Cookbook',1,39.99,'Provides a complete, solutionsoriented guide to the challenges most often faced by PHP developersrnWritten specifically for experienced Web developers, the book offers real-world solutions 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 carpeta c:/appserver/www/(nombre de tu carpeta) 4.- Empesaremos creando un archivo PHP se llamara Index.php y le agregaremos este codigo.

<? include ('book_sc_fns.php');

session_start(); do_html_header("Bienvenido a la Tienda de Cocinando con JADA"; echo "<p>Selecciona Libros:</p>"; $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.

<? function process_card($card_details) { return true; } function insert_order($order_details) { global $total_price; global $cart; extract($order_details);

if(!$ship_name&&!$ship_address&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ ship_country) {

$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 where name = '$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 where name = '$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"; else return false; $date = date("Y-m-d"; $query = "insert into orders values

('', $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 where customerid = $customerid and amount > $total_price-.001 and amount < $total_price+.001 and date = '$date' and order_status = 'PARTIAL' and ship_name = '$ship_name' and ship_address = '$ship_address' and ship_city = '$ship_city' and ship_state = '$ship_state' and ship_zip = '$ship_zip' and ship_country = '$ship_country'"; $result = mysql_query($query); if(mysql_numrows($result)>0) $orderid = mysql_result($result, 0, "orderid"; else return false;

foreach($cart as $isbn => $quantity) { $detail = get_book_details($isbn); $query = "delete from order_items where orderid = '$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; }

return $orderid; } ?> 6.-Vamos a crear otro archivo se llamara output_fns.php que sera nuestro archivo mas extenso.

<? function do_html_header($title = '') { global $total_price; global $items; if(!$items) $items = "0"; if(!$total_price) $total_price = "0.00"; ?> <html> <head> <title><?=$title?></title> <style> 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 } </style> </head> <body> <table width=100% border=0 cellspacing = 0 bgcolor=#cccccc> <tr> <td rowspan = 2> <a href = "index.php"><img src="images/Book-O-Rama.gif" alt="Bookorama" border=0 align=left valign=bottom height = 60 width = 247></a>

</td> <td align = right valign = bottom> <? if(session_is_registered("admin_user") echo "&nbsp;"; else echo "Total Items = $items"; ?> </td> <td align = right rowspan = 2 width = 135> <? if(session_is_registered("admin_user") display_button("logout.php", "log-out", "Log Out"; else display_button("show_cart.php", "view-cart", "View Your Shopping Cart"; ?> </tr> <tr> <td align = right valign = top> <? if(session_is_registered("admin_user") echo "&nbsp;"; else echo "Precio Total = $".number_format($total_price,2); ?> </td> </tr> </table> <? if($title) do_html_heading($title); } function do_html_footer() { // print an HTML footer ?> </body> </html> <? }

function do_html_heading($heading) { // print heading ?> <h2><?=$heading?></h2> <? } function do_html_URL($url, $name) { // output URL as link and br ?> <a href="<?=$url?>"><?=$name?></a><br> <? } function display_categories($cat_array) { if (!is_array($cat_array)) { echo "No hay categoras actualmente disponibles<br>"; return; } echo "<ul>"; foreach ($cat_array as $row) { $url = "show_cat.php?catid=".($row["catid"]); $title = $row["catname"]; echo "<li>"; do_html_url($url, $title); } echo "</ul>"; echo "<hr>"; } function display_books($book_array) {

//display all books in the array passed in if (!is_array($book_array)) { echo "<br>No books currently available in this category<br>"; } else { //create table echo "<table width = "100%" border = 0>"; //create a table row for each book foreach ($book_array as $row) { $url = "show_book.php?isbn=".($row["isbn"]); echo "<tr><td>"; if (@file_exists("images/".$row["isbn"].".jpg") { $title = "<img src="images/".($row["isbn"]).".jpg" border=0>"; do_html_url($url, $title); } else { echo "&nbsp;"; } echo "</td><td>"; $title = $row["title"]." de ".$row["author"]; do_html_url($url, $title); echo "</td></tr>"; } echo "</table>"; } echo "<hr>"; } function display_book_details($book) { // display all details about this book if (is_array($book))

{ echo "<table><tr>"; //display the picture if there is one if (@file_exists("images/".($book["isbn"]).".jpg") { $size = GetImageSize("images/".$book["isbn"].".jpg"; if($size[0]>0 && $size[1]>0) echo "<td><img src="images/".$book["isbn"].".jpg" border=0 ".$size[3]."></td>"; } echo "<td><ul>"; echo "<li><b>Autor:</b> "; echo $book["author"]; echo "<li><b>ISBN:</b> "; echo echo echo echo echo echo } else $book["isbn"]; "<li><b>Nuestro Precio:</b> "; number_format($book["price"], 2); "<li><b>Descripcin:</b> "; $book["description"]; "</ul></td></tr></table>";

echo "Los detalles de este libro no pueden ser mostrados en este momento."; echo "<hr>"; } function display_checkout_form() { //display the form that asks for name and address ?> <br> <table border = 0 width = 100% cellspacing = 0> <form action = purchase.php method = post> <tr><th colspan = 2 bgcolor="#cccccc">Su informacin</th></tr> <tr> <td>Nombre</td> <td><input type = text name = name value = "campo obligatorio" 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 = 40 size = 40></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr> <td>Direccin</td> <td><input type = text name = address value ="campo obligatorio" 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 = 40 size = 40></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr> <td>Ciudad/Suburbio</td> <td><input type = text name = city value = "campo obligatorio" 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></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr> <td>Estado/Provincia</td> <td><input type = text name = state value ="campo obligatorio"

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></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr> <td>Cdigo Postal o Cdigo Zip</td> <td><input type = text name = zip value = "campo obligatorio" onFocus="clearText(this)" maxlength = 10 size = 40></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr> <td>Pas</td> <td><input type = text name = country value = "campo obligatorio" 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></td> <script> function clearText (thefield){ if(thefield.defaultValue==thefield.value) thefield.value="" } </script> <tr><th colspan = 2 bgcolor="#cccccc">Direccin de envo (dejar en blanco si es el de arriba)</th></tr> <tr> <td>Nombre</td> <td><input type = text name = ship_name value = "" maxlength = 40 size =

40></td> </tr> <tr> <td>Direccin</td> <td><input type = text name = ship_address value = "" maxlength = 40 size = 40></td> </tr> <tr> <td>Ciudad/Suburbio</td> <td><input type = text name = ship_city value = "" maxlength = 20 size = 40></td> </tr> <tr> <td>Estado/Provincia</td> <td><input type = text name = ship_state value = "" maxlength = 20 size = 40></td> </tr> <tr> <td>Cdigo Postal o Cdigo Zip</td> <td><input type = text name = ship_zip value = "" maxlength = 10 size = 40></td> </tr> <tr> <td>Pas</td> <td><input type = text name = ship_country value = "" maxlength = 20 size = 40></td> </tr> <tr> <td colspan = 2 align = center> <b>Por favor pulsar compar para confirmar su compra, o Continuar comprando para aadir o eliminar artculos</b> <? display_form_button("purchase", "Purchase These Items"; ?> </td> </tr> </form> </table><hr> <? }

function display_shipping($shipping) { // display table row with shipping cost and total price including shipping global $total_price; ?> <table border = 0 width = 100% cellspacing = 0> <tr><td align = left>Envo</td> <td align = right> <?=number_format($shipping, 2); ?></td></tr> <tr><th bgcolor="#cccccc" align = left>TOTAL INCLUIDO ENVO</th> <th bgcolor="#cccccc" align = right>$<?=number_format($shipping+$total_price, 2); ?></th> </tr> </table><br> <? } function display_card_form($name) { //display form asking for credit card details ?> <table border = 0 width = 100% cellspacing = 0> <form action = process.php method = post> <tr><th colspan = 2 bgcolor="#cccccc">Detalles Tarjeta Crdito</th></tr> <tr> <td>Tipo</td> <td><select name = card_type><option>VISA<option>MasterCard<option>American Express</select></td> </tr> <tr> <td>Nmero</td> <td><input type = text name = card_number value = "" maxlength = 16 size = 40></td> </tr> <tr> <td>Cdig AMEX code (si se requiere)</td> <td><input type = text name = amex_code value = "" maxlength = 4 size =

4></td> </tr> <tr> <td>Fecha Expiracin</td> <td>Mes <select name = card_month><option>01<option>02<option>03<option>04<option>05<opti on>06<option>07<option>08<option>09<option>10<option>11<option>12 </select> ao <select name = card_year><option>00<option>01<option>02<option>03<option>04<option >05<option>06<option>07<option>08<option>09<option>10</select></td > </tr> <tr> <td>Nombre en Tarjeta</td> <td><input type = text name = card_name value = "<?=$name; ?>" maxlength = 40 size = 40></td> </tr> <tr> <td colspan = 2 align = center> <b>Por favor pulsa comprar para confirmar tu compra, o Continuar Comprando para aadir o eliminar artculos</b> <? display_form_button("purchase", "Purchase These Items"; ?> </td> </tr> </table> <? }

function display_cart($cart, $change = true, $images = 1) { // display items in shopping cart // optionally allow changes (true or false) // optionally include images (1 - yes, 0 - no) global $items;

global $total_price; echo "<table border = 0 width = 100% cellspacing = 0> <form action = show_cart.php method = post> <tr><th colspan = ". (1+$images) ." bgcolor="#cccccc">Item</th> <th bgcolor="#cccccc">Price</th><th bgcolor="#cccccc">Quantity</th> <th bgcolor="#cccccc">Total</th></tr>"; //display each item as a table row foreach ($cart as $isbn => $qty) { $book = get_book_details($isbn); echo "<tr>"; if($images ==true) { echo "<td align = left>"; if (file_exists("images/$isbn.jpg") { $size = GetImageSize("images/".$isbn.".jpg"; if($size[0]>0 && $size[1]>0) { echo "<img src="images/".$isbn.".jpg" border=0 "; echo "width = ". $size[0]/3 ." height = " .$size[1]/3 . ">"; } } else echo "&nbsp;"; echo "</td>"; } echo "<td align = left>"; echo "<a href = "show_book.php?isbn=".$isbn."">".$book["title"]."</a> de ".$book["author"]; echo "</td><td align = center>$".number_format($book["price"], 2); echo "</td><td align = center>"; // if we allow changes, quantities are in text boxes if ($change == true) echo "<input type = text name = "$isbn" value = $qty size = 3>"; else

echo $qty; echo "</td><td align = center>$".number_format($book["price"]*$qty,2)."</td></tr>n"; } // display total row echo "<tr> <th colspan = ". (2+$images) ." bgcolor="#cccccc">&nbsp;</td> <th align = center bgcolor="#cccccc"> $items </th> <th align = center bgcolor="#cccccc"> $".number_format($total_price, 2). "</th> </tr>"; // display save change button if($change == true) { echo "<tr> <td colspan = ". (2+$images) .">&nbsp;</td> <td align = center> <input type = hidden name = save value = true> <input type = image src = "images/save-changes.gif" border = 0 alt = "Save Changes"> </td> <td>&nbsp;</td> </tr>"; } echo "</form></table>"; } function display_login_form() { // dispaly form asking for name and password ?> <form method=post action="admin.php"> <table bgcolor=#cccccc> <tr> <td>Nombre Usuario:</td>

<td><input type=text name=username></td></tr> <tr> <td>Contrasea:</td> <td><input type=password name=passwd></td></tr> <tr> <td colspan=2 align=center> <input type=submit value="Log in"></td></tr> <tr> </table></form> <? } function display_admin_menu() { ?> <br> <a href="index.php">Ir al sitio principal</a><br> <a href="insert_category_form.php">Aadir una nueva categora</a><br> <a href="insert_book_form.php">Aadir un nuevo libro</a><br> <a href="change_password_form.php">Cambiar la contrasea de Admin</a><br> <? } function display_button($target, $image, $alt) { echo "<center><a href="$target"><img src="images/$image".".gif" alt="$alt" border=0 height = 50 width = 135></a></center>"; } function display_form_button($image, $alt) { echo "<center><input type = image src="images/$image".".gif" alt="$alt" border=0 height = 50 width = 135></center>"; } ?>

7.- Crearemos otro archivo este archivo se llamara process.php

<? include ('book_sc_fns.php'); session_start(); do_html_header("Caja de pago" ; if($cart&&$card_type&&$card_number&&$card_month&&$card_year&&$card_ name ) { display_cart($cart, false, 0); display_shipping(calculate_shipping_cost()); if(process_card($HTTP_POST_VARS)) { session_destroy(); echo "Gracias por confiar en nosotros. Su pedido ha sido tramitado."; display_button("index.php", "continue-shopping", "Continue Shopping"; } else { echo "No hemos podido procesar su tarjeta, Por favor contacte con los emisores de la tarjeta o intntalo de nuevo."; display_button("purchase.php", "back", "Back"; } } else { echo "No has cubierto todos los campos, por favor, intntalo de nuevo.<hr>"; display_button("purchase.php", "back", "Back"; } do_html_footer(); ?>

8.- Crearemos un archivo que se llamara purchase.php <? include ('book_sc_fns.php'); session_start(); do_html_header("Caja de pago"; if($cart&&$name&&$address&&$city&&$zip&&$country) { if( insert_order($HTTP_POST_VARS)!=false ) { display_cart($cart, false, 0); display_shipping(calculate_shipping_cost()); display_card_form($name); display_button("show_cart.php", "continue-shopping", "Continue Shopping"; } else { echo "Could not store data, please try again."; display_button("checkout.php", "back", "Back"; } } else { echo "You did not fill in all the fields, please try again.<hr>"; display_button("checkout.php", "back", "Back"; } do_html_footer(); ?> 9.-crearemos el siguiente archivo show_book.php

<? include ('book_sc_fns.php'); session_start(); $book = get_book_details($isbn); do_html_header($book["title"]); display_book_details($book); $target = "index.php"; if($book["catid"]) { $target = "show_cat.php?catid=".$book["catid"]; } if( check_admin_user() ) { display_button("edit_book_form.php?isbn=$isbn", "edit-item", "Edit Item"; display_button("admin.php", "admin-menu", "Admin Menu"; display_button($target, "continue", "Continue"; } else { display_button("show_cart.php?new=$isbn", "add-to-cart", "Add ".$book["title"]." To My Shopping Cart"; display_button($target, "continue-shopping", "Continue Shopping"; } do_html_footer(); ?> 9.- crearemos otro archivo que sera show_cart.php

<? include ('book_sc_fns.php'); session_start(); if($new)

{ 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 "<p>No hay artculos en tu carro";

echo "<hr>"; } $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-tocheckout", "Go To Checkout"; do_html_footer(); ?> 10.- creamos otro archivo sera show_cat.php que es completamente diferente al de show_cart.php

<? include ('book_sc_fns.php'); session_start(); $name = get_category_name($catid); do_html_header($name); $book_array = get_books($catid); display_books($book_array); if(session_is_registered("admin_user") { display_button("index.php", "continue", "Continue Shopping"; display_button("admin.php", "admin-menu", "Admin Menu";

display_button("edit_category_form.php?catid=$catid", "edit-category", "Edit Category"; } else display_button("index.php", "continue-shopping", "Continue Shopping"; do_html_footer(); ?>

11.- creamos el siguiente archivo book_fns.php <? function calculate_shipping_cost() { return 20.00; } function get_categories() { $conn = db_connect(); $query = "select catid, catname from categories"; $result = @mysql_query($query); if (!$result) return false; $num_cats = @mysql_num_rows($result); if ($num_cats ==0) return false; $result = db_result_to_array($result); return $result; } function get_category_name($catid) { $conn = db_connect(); $query = "select catname from categories

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)

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; }

?> 12.- creamos otro archivo y sera book_sc_fns.php con el siguiente codigo <? include_once("db_fns.php"; include_once("data_valid_fns.php"; include_once("output_fns.php"; include_once("book_fns.php"; include_once("user_auth_fns.php"; include_once("admin_fns.php"; include_once("order_fns.php"; ?> 13.-creamos el siguiente codigo checkout.php <? include ('book_sc_fns.php'); session_start(); do_html_header("Caja de pago"; if($cart&&array_count_values($cart)) { display_cart($cart, false, 0); display_checkout_form(); } else echo "<p>No hay artculos en su carrito"; display_button("show_cart.php", "continue-shopping", "Continue Shopping"; do_html_footer(); ?>

14.- creamos el siguiente archivo data_valid_fns.php <? function filled_out($form_vars) { foreach ($form_vars as $key => $value) { if (!isset($key) || ($value == "") return false; } return true; } function valid_email($address) { if (ereg("^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$", $address)) return true; else return false; } ?>

15.- final mente creamos un ultimo archivo que se llamara db_fns.php <? function db_connect() { $result = @mysql_pconnect("localhost", "root", "12345678"; if (!$result) return false; if (!@mysql_select_db("Sql18226_1") return false;

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 EXPLORADOR Y PONDREMOS LA SIGUIENTE DIRECCION QUE SERA http://localhost/tienda_online/index.php localhost es el servidor tienda_online es el nombre de la carpeta que creamos en www dentro de appsever index.php es el primer formulario PHP que creamos. DISCULPEN PERO NO SE COMO METER IMAGENES PERO SI NECESITAN AYUDA ESCRIBAN SEGURAMENTE LES PUEDO AYUDAR. JIMMYMIENTRAS EL CONOCIMIENTO LO COMPARTAS CON TODOS, MAS APRENDEREMOS CERO EGOISMO JIMMY

Potrebbero piacerti anche