PHP - Need Some Help With A Commerce Problem
Hey everyone. I am making a site for my brother's band and having some trouble with the checkout to paypal. Unfortunately in layout I missed a pretty important variable, the size on shirts. I am trying to add it in as a drop down option just before submitting to paypal but I can't get it to show up on paypal and thus will have no idea what size they are ordering. The site is pretty basic and primitive but I really need this info on the checkout. Here is a link to the temporary site where i'm trying to get this to work:
http://www.theblack44s.com/t/index3.php and this is what is up and running now: http://www.theblack44s.com/Merchant%20pages/apparel/index3.php this is the code i'm working on in cart.php: Code: [Select] <?php require "dbconcart.php"; session_start(); //session_destroy(); $page = 'index.php'; $value2 = $_POST['size']; //add to cart function if (isset($_GET['add'])) { $quantity = mysql_query('SELECT id, quantity, imageurl FROM apparel WHERE id='.mysql_real_escape_string((int)$_GET['add'])); while ($quantity_row = mysql_fetch_assoc($quantity)) { if ($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) { $_SESSION['cart_'.(int)$_GET['add']]+='1'; } } header('Location: '.$page); } //remove from cart if (isset($_GET['remove'])) { $_SESSION['cart_'.(int)$_GET['remove']]--; header('Location: '.$page); } //delete from cart if (isset($_GET['delete'])) { $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location: '.$page); } // products function products() { $get = mysql_query('SELECT id, name, item_number, description, price, shipping FROM apparel WHERE quantity > 0 ORDER BY id DESC'); if (mysql_num_rows($get)==0) { echo "There are no products to display!"; } else { while ($get_row = mysql_fetch_assoc($get)) { echo $get_row['name'].'<br />'; echo $get_row['item_number'].'<br />'; echo $get_row['description'].'<br />'; echo 'Price: '.number_format($get_row['price'], 2).'<br />'; echo 'Shipping: '.number_format($get_row['shipping'], 2); echo '<a href="cart.php?add='.$get_row['id'].'">Add to cart</a></p>'; } } } //paypal function function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5)=='cart_') { $id = substr($name, 5, strlen($name)-5); $get = mysql_query('SELECT id, name, item_number, price, shipping FROM apparel WHERE id='.mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$get_row['item_number'].'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">'; echo '<input type="hidden" name="size_" value="$_POST'.$value2.']">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">'; echo '<input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'">'; echo '<input type="hidden" name="shipping2_'.$num.'" value="'.$get_row['shipping'].'">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } //cart function function cart() { foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5)=='cart_') { $id = substr($name, 5, (strlen($name)-5)); $get = mysql_query('SELECT id, name, price, imageurl FROM apparel WHERE id='.mysql_real_escape_string((int)$id)); while ($get_row = mysql_fetch_assoc($get)) { $sub = $get_row['price']*$value; echo $get_row['name'].' x '.$value.' @ $'.number_format($get_row['price'], 2).' = $'.number_format($sub, 2).'<br />'; ?> <html> <body> <form action="size.php" method="post" name="size"> <label>Size <select name="size"> <option selected="selected">Select</option> <option value="youth">Youth (for the brats)</option> <option value="small">Small (petite)</option> <option value="medium">Medium (average)</option> <option value="large">Large (healthy)</option> <option value="xlarge">X Large (large)</option> <option value="xxlarge">XX Large (full figured</option> <option value="xxxlarge">XXX Large (huge)</option> <option value="xxxxlarge">XXXXLarge (DAMN!!)</option> </select> <input type="hidden" name="size" value="selected" /> <input type="hidden" name="size" value="submit()" /> </label> </form> </body> </html> <?php echo '<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[delete]</a><br />'; } } $total += $sub; } } //cart totals and paypal function if ($total==0) { echo "Your cart is empty."; } else { echo '<p><b>Total: $ '.number_format($total, 2).'</b></p>'; ?> <p> <form action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="webmaster@theblack44s.com"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="hidden" name="size" value="<?php echo $value2; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" target="_blank" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> </p> <?php } } ?> Similar TutorialsHi all, I'm a bit of a newbie to this type of website and would be extremely grateful for any help on this as it's causing considerable headaches! I've been working on an e-commerce (Online Shop) website based on the site found he http://www.phpwebcommerce.com/ I have been building it into a template from the original shop that was essentially a static website with links to paypal for the cart etc. Now I am trying to add an extra function to the site but cant get my head around the logic to making this work and I know it can be done! The shop is to sell mainly shoes with some accessories. So I understand that shoes obviously come in a variety of sizes, and each size needs to have its own product ID in the MySQL DB so I can show whether it is in stock etc. What I cant figure out is how to firstly make an easy way of adding the shoes different sizes (for eg 10 shoes of the same type in sizes 40-49) to the DB in one hit instead of filling in the same form 10 times but with different sizes. I have the simple form already made and working successfully. My thoughts are to add check box in the form to say I'm adding multiple shoes that tells the process to look for values in text areas for starting shoe size and last shoe size. The process then takes the start size from the end size giving the number of times to loop the process. It then loops the process for each size using the same information... Logically this works but I'm not sure how to code this on what I have. I have attached the files used directly in this. Secondly how do I group the shoes on the front end. Now each product on the front end currently will display a simple message instead of add to cart when the stock = 0, or the product has been made as available on request. I would like to group the shoes of the same type to have a drop down menu showing the available sizes. When a size is selected it needs to query the DB for available stock and either show the 'Add to cart' or 'Call to order' options. Anything else you might need to help with this let me know. I'm keen to get this bit done so I can get the site live! Thanks in advance Hi, I got problems on my website http://www.tranceprofile.com/ When I want to go to my Storeadmin page (http://www.tranceprofile.com/storeadmin/) I get this: Warning: session_start() [function.session-start]: open(/public/tmp/sess_64fb1b28e78195d89731106458023ab4, O_RDWR) failed: No such file or directory (2) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at /public/sites/www.tranceprofile.com/storeadmin/index.php:5) in /public/sites/www.tranceprofile.com/storeadmin/index.php on line 7 Warning: Unknown: open(/public/tmp/sess_64fb1b28e78195d89731106458023ab4, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/public/tmp) in Unknown on line 0 Can someone help me? Here is my code Code: [Select] <?php session_start(); if (!isset($_SESSION["manager"])) { header("location: admin_login.php"); exit(); } // Be sure to check that this manager SESSION value is in fact in the database $managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters // Run mySQL query to be sure that this person is an admin and that their password session var equals the database information // Connect to the MySQL database include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person // ------- MAKE SURE PERSON EXISTS IN DATABASE --------- $existCount = mysql_num_rows($sql); // count the row nums if ($existCount == 0) { // evaluate the count echo "Your login session data is not on record in the database."; exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Admin Area</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../template_header.php");?> <div id="pageContent"><br /> <div align="left" style="margin-left:24px;"> <h2>Hello store manager, what would you like to do today?</h2> <p><a href="inventory_list.php">Manage Inventory</a><br /> <a href="#">Manage Blah Blah </a></p> </div> <br /> <br /> <br /> </div> <?php include_once("../template_footer.php");?> </div> </body> </html> I am relatively new to php but I have been learning since the end of 2011. At the moment, I am currently developing an E-Commerce website for a customer, using the Larry Ullman book "Effortless E-Commerce' as a guide. I am hitting many brick walls at the moment though. But before I state my long winded problem, I have attached all my work done thus far to this message. HERES THE PROBLEM... I have created a series of includes such as config.inc.php, form_functions.inc.php, login.inc.php and login_form.inc.php. They are included/required with most of my other files. However I have some major issues; 1. This is the code for my logout.php file; Code: [Select] <?php require ('./includes/config.inc.php'); // If the user isn't logged in, redirect them: redirect_invalid_user(); // Destroy the session: $_SESSION = array(); // Destroy the variables. session_destroy(); // Destroy the session itself. setcookie (session_name(), '', time()-300); // Destroy the cookie. // Include the header file: $page_title = 'Logout'; include ('includes/header.html'); // Print a customized message: include ('includes/main.html'); echo '<h3>Logged Out</h3><p>Thank you for visiting. You are now logged out. Please come back soon!</p>'; // Footer file needs the database connection: require (MYSQL); // Include the HTML footer: include ('includes/footer.html'); ?> At the moment, I cannot determine if a user is logged in/when they logout, I cannot determine if there is an active session and also, when I log into the site, I have a database with values yet it seems to let any Tom, Dick and Harry onto the site to log in even though they are not stored in the database. I apologise if this sounds confusing but I really need some major league help. Help would be greatly appreciated I have an array that needs to display all titles and allow for a user to view titles based on the category, title, etc . I tried using the print_r() function but it didn't display the titles in a clean list. The only tutorials I've found utilize sql and i need to complete this without using SQL. Code: [Select] $books = array(); array_push($books,array("category" => "Nonfiction","title" => "The Innocent Man","author" => "Grisham","publisher" => "McGraw-Hill","price" => "34.99","isbn" => "5985420166")); array_push($books,array("category" => "Business","title" => "How to Make Money","author" => "Richy","publisher" => "Prentice-Hall","price" => "49.99","isbn" => "8754739342")); array_push($books,array("category" => "Romance","title" => "Twice Kissed","author" => "Jackson","publisher" => "McGraw-Hill","price" => "14.99","isbn" => "5671230987")); Hey guys I had created a while ago a script for my friend where you can buy points and then redeem stuff with those points, i'm looking for ways to keep my site secu currently what i have done- - protected all mysql queries with mysql_real_escape_string, strip_tags, and addslashes - have a valid SSL certificate on my website - checked if emails are valid for account creation what else can I do? Thank you. Hey guys, I got a tough one. I've been researching for days, weeks even, to try and solve this. And I'm sure I'm going to kick myself if/when I get a solution. I've set up an ecommerce website from scratch (no prestashop, oscommerce, none of that), and I need to figure out how to decrease price on quantity. Ex; Umbrellas are $12.00 a piece. If you order 2 dozen (24) Umbrellas, they are only $10.00 a piece. I can't seem to figure out a way to make it work.. I have set up in my database the following columns. p - base price ($12) p1 - price after first increment ($10) q1 - quantity of first break (24) p2 q2 p3 q3 Hit me with your best shot. I am building an e-commerce site and I am aiming to create a front end displaying my products with an option for customers to buy them, and have a content management system as a back end for an admin to edit product information.
Currently I am storing information about my products on a mysql database. I access and display the product info using a while loop. Below is a simplified version of what I am doing without any html to style it. This code will go through the database and each iteration will go the to the next row and display the info about the next product.
$query = mysql_query("SELECT * FROM truffleProducts"); while ($row = mysql_fetch_array($query)) { $id = $row['id']; $name = $row{'Name'}; $price = $row{'Price'}; $desc = $row{'Description'}; echo $id; echo $name; echo $price; echo $desc; }I have began to implement a 'buy' button so that customers are able to click on a button next to the product info and purchase it. However I have come across a problem which is where my program won't be able to tell which product you have selected as the number stored in the $id variable will just be the last product it has fetched from the database. I can't differentiate between all the product's buy buttons, so it will impossible to place an order for a customer with the current system I have. Can any one tell me how to get the id number of the specific product that a user has selected? I only started learning PHP a month or two ago so assume I know nothing This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=276607.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=321270.0 Guys thanks for helping me solve the problem i had but now i have another problem and i am lost. i have included the code below for you to have overview.
This is the code:
<table style="width:100%; margin-left:auto; margin-right:auto"> Hows it going guys. I am currently having a problem. I had a program that worked. I migrated the website and now the program is broken. Any time i try to run it, i get this error: Quote Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/thegoo20/public_html/class/wordgame/wordgame.php on line 31 Here is the code at that point: Code: [Select] function changeword(){ $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['word'] = $totalwords[rand(0, count($totalwords)-1)]; $_SESSION['scrambled'] = str_shuffle($_SESSION['word']); } where line 31 is the while statement. Any help would be appreciated. Thanks I have having a problem getting a mysql query to work. If I just use mysql_query it looks like this and works fine: INSERT INTO schedule (schedule_pk, schedule_month, schedule_day, schedule_year, schedule_hour, schedule_minute, schedule_type, employeenumber) VALUES ( NULL, 10, 10, 1999, 12, 6, 'DayIn', 3); If I put it through mysql_real_escape_string it turns it to this and does not work when I put it into mysql_query: INSERT INTO schedule (schedule_pk, schedule_month, schedule_day, schedule_year, schedule_hour, schedule_minute, schedule_type, employeenumber) VALUES ( NULL, 10, 10, 1999, 12, 6, \'DayIn\', 3); aka: $query = "INSERT INTO...." mysql_query($query); that works, but: $query = "INSERT INTO...." $sqlQuery = mysql_real_escape_string($query, $con); mysql_query($sqlQuery); results in the error. mysql_query($query); The error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'DayIn\', 3)' at line 1 I do not receive email for my published php file which is: <?php ///// easend.php ///// $youremail = "acdelco40108@yahoo.com"; /*put the email address here, between quotes, the email address you want the message sent to*/ $to = $youremail; $email = $_POST['EMail']; $name2 = $_POST['Name']; $street2 = $_POST['Street']; $city2 = $_POST['City']; $state2 = $_POST['State']; $zip2 = $_POST['Zip']; $Phone = $_POST['Home_Phone']; $Cell = $_POST['Cell_Phone']; $education = $_POST['email1']; $comments = $_POST['email2'] ; $headers = "From:" . $email; $fields = array(); $fields{"Name"} = "Name"; $fields{"Street"} = "Street"; $fields{"City"} = "City"; $fields{"State"} = "State"; $fields{"Zip"} = "Zip"; $fields{"Home_Phone"} = "Home Phone"; $fields{"Cell_Phone"} = "Cell Phone"; $fields{"EMail"} = "Email"; $fields{"email1"} = "Education"; $fields{"email2"} = "Comments"; $subject = "We have received the following information from your employment application"; $body = "We have received the following information from your employment application:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_POST[$a]); } mail ($to, $subject, $body, $headers); //send mail to owner #end create email vars $headers = "From:" . $to; mail ($email, $subject, $body, $headers); //send mail to user #end create email vars echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=ThankYou.html\"></head>"; ?> Okey so i made a table that you put your name,author,and message when you submit it , it echoes a table with the name,author and message written (and it also echoes a delete buttom,so delete this post oif necessary) im new to php and i have been with this problem for a couple of weeks so i guess its time to ask for some help the problem is that i dunnot know how to make my delete buttom work! i tried if statement but it dosent work i also tried ternary operation and dint work :S i read that there is something like $post[ID](and this is supposed to get the ID of the post submmited, and delete it) im not sure, im so confused! help! XD this is the code <?php $tittle=$_POST['tittle']; $author=$_POST['author']; $message=$_POST['message']; if ($_POST['submitnews']){ $currentdate= date("y-m-d"); $currenttime=date("H:i:s",strtotime("-6 hours")); $post=mysql_query("INSERT INTO news VALUES('','$tittle','$author','$message','$currentdate','$currenttime')"); echo"Posted!"; } $select=mysql_query("SELECT * FROM news ORDER BY id DESC"); while ($row= mysql_fetch_assoc($select)) { $id=$row['id']; $tittle=$row['tittle']; $author=$row['author']; $message=$row['message']; $date=$row['date']; $time=$row['time']; if ($_SESSION['admin']) { echo " <table width='488px' id='news_table'> <tr> <td> </td> <td> <center><font size='5'>$tittle</font></center><br> </td> </tr> <tr> <td> </td> <td> $message </td> </tr> <tr> <td> </td> <td> <font size='1'>Posted By:<font color='green'>$author</font> on <font color='gray'>$date</font> at <font color='gray'>$time</font></font> <input name='delete' type='submit' value='delete'> <td> </td> </tr><br><br> </table>"; I am trying to save this an an xml document but am getting this error when I try to open the xml file "feed.xml" - "XML Parsing Error: no element found" $xml = '<rss version="2.0"> <channel> <title> RSS Feed</title> <link></link> <description>the best industry-lead opinions</description> <language>en-us</language> </channel> </rss>"; $xml2 = new DOMDocument('1.0'); $xml2->Load($xml); $xml2->save("feed.xml"); I Have An error on line 42 not sure what it is can any one tell? $foundnum = mysql_num_rows($run); I am trying to understand PHP OOP and I have some code that is not working. here is the error code. Code: [Select] Parse error: parse error, expecting `T_FUNCTION' in C:\wamp\www\testing\armor_lib.php on line 11 And here is the armor_lib.php file: <?php class armor { // Head public $head; public $torso; public $pants; public $gloves; public $boots; // new stuff here class head extends armor { function __construct($head){ $this->set_head($head); } } // Torso class torso extends armor { function __construct($torso){ $this->set_torso($torso); } } // Pants class pants extends armor { function __construct($pants){ $this->set_pants($pants); } } // Gloves class gloves extends armor { function __construct($gloves){ $this->set_gloves($gloves); } } // Boots class boots extends armor { function __construct($boots){ $this->set_boots($boots); } } } ?> And here is the php in the armor.php file I have: <?php $head = new armor("Leather Helm"); $torso = new armor("Leather Shirt"); $pants = new armor("Leather Pants"); $gloves = new armor("Chain Mail Gloves"); $boots = new armor("Leather Boots"); echo "You are wearing: " . $head->get_head() . "on your Head"; echo "<br />"; echo "You are wearing: " . $torso->get_torso() . "on your Torso"; echo "<br />"; echo "You are wearing: " . $pants->get_pants() . "on your Legs"; echo "<br />"; echo "You are wearing: " . $gloves->get_gloves() . "on your Hands"; echo "<br />"; echo "You are wearing: " . $boots->get_boots() . "on your Feet"; ?> Any Help in understanding this will be much appreciated. Thanks. Hi all. When I typed symbol ' in my textarea , after I submit it and view for what I typed , it will automatically add a slash in front of the ' . Such as the message is "I'm fine" , then it will turn out as "I\'m fine". Can I know what is the problem ? and how can I solve it? Thanks for every reply . Hi Guys, I am having an issue with an if statement, I cant get it to go true, even though it clearly is! Please excuse the messy code, im pulling my hair out here! $itemprice[0] = 8.99; $itemprice[1] = 19.95; $itemprice[2] = 8.99; print_r($itemprice); echo "<BR>"; $x=0; foreach($itemprice AS $val) { echo gettype($val) .$val. "<br>"; if($val == 8.99) { $x++; $freecount++; } } echo $x; outputs correctly: Array ( => 8.99 [1] => 19.95 [2] => 8.99 ) double8.99 double19.95 double8.99 x = 2 replacing: $newtotal = add_to_price($id, $non_disc); $itemprice[] = $newtotal - $non_disc; print_r($itemprice); echo "<BR>"; $x=0; foreach($itemprice AS $val) { echo gettype($val) .$val. "<br>"; if($val == 8.99) { $x++; $freecount++; } } echo $x; The add to price function returns a running total, the take away gives me the current item price in a for loop to build the array. Output: Array ( => 8.99 [1] => 19.95 [2] => 8.99 ) double8.99 double19.95 double8.99 x = 1 The problem? Well when I build the array up automatically it still prints the same, has the same datatype, yet the if statement does not catch the second 8.99 value? Please accept my apologies for this post, it is my first ever and i've been doing this for 10 years now, i have never been this stumped on something so simple, I can only think it is a datatype error but i have tried apostrophes in the if, make no difference. All help massively gratefully received. Please email me if you want to see it in action... |