PHP - Suggestions Please
Hi
I was playing with a poll, but for some reasons it won't email me(the bottom most part). Where did I go wrong? Also any suggestions on how to improve this? Thanks your the best guys! <?php include('config.php'); $name = strip_tags($_POST['name']); $email = $_POST['email']; $qst_id=strip_tags($_POST['qst_id']); //if no ajax $opt = strip_tags($_POST['opt']); $s_id = $_SERVER['REMOTE_ADDR']; //validate email if (!preg_match('/^.+@.+\..{2,3}$/',$email)); { $email = 'email was blocked'; } if (strlen($name) >= 50) { $name = 'name was blocked'; } if ($opt == '') { $vote ="no"; } elseif (($opt=='Yes') || ($opt=='No')) { $qt=mysql_query("insert into plus_poll_ans(s_id,qst_id,opt) values('".$s_id."','".$qst_id."','".$opt."')"); } else { $vote = "no"; } echo "<font size='2' face='Verdana' color='#000000' style='font-size:1.2em;'> Declaration of Faith</font>"; $qst_id=1; // change this to change the poll /* Find out the question first */ $fg=mysql_query("select qst from plus_poll where qst_id='".$qst_id."'"); $row=mysql_fetch_object($fg); echo "<br><b><br>$row->qst</b><br>"; // display the question /* for percentage calculation we will find out the total number of answers ( options submitted ) given by the visitors */ $rt=mysql_num_rows(mysql_query("select ans_id from plus_poll_ans where qst_id='".$qst_id."'")); /* Find out the answers and display the graph */ $query="select count(*) as no,qst,plus_poll_ans.opt from plus_poll,plus_poll_ans where plus_poll.qst_id=plus_poll_ans.qst_id and plus_poll.qst_id='".$qst_id."' group by opt desc "; $rs=mysql_query($query); //count the answers by yes or no $count= "SELECT opt, count(opt) FROM plus_poll_ans GROUP BY opt desc"; $result = mysql_query($count) or die(mysql_error()); //separate the results while($row = mysql_fetch_array($result)){ $total_opt[] = $row['count(opt)']; } // Print out result echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' >"; $i = 0; while($noticia = mysql_fetch_array($rs)){ echo "<tr> <td width='5%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>$noticia[opt]</font></td>"; $width2=$noticia['no'] *10 ; /// change here the multiplicaiton factor ////////// $ct=($noticia[no]/$rt)*100; $ct=sprintf ("%01.2f", $ct); // number formating echo " <td width='20%' bgcolor='#F1F1F1'> <font size='1' face='Verdana' color='#000000'>($ct %)</font></td><td width='60%' align='left' bgcolor='#F1F1F1'> <img src='graph.jpg' height=10 width=$width2>"; echo "</td><td width='15%' align='right'>"; echo "<font size='1' face='Verdana' color='#000000'>".$total_opt[$i]; echo " votes"; echo "</font></td>"; echo "</tr>"; echo "<tr> <td bgcolor='#ffffff' colspan=2>"; echo "</td>"; echo "</tr>"; $i=$i+1; } echo "<tr><td></td><td></td><td><font size='1' face='Verdana' color='#000000'>Total Votes:</font></td><td align='right'>"; //count the total votes $count = 'select count(ans_id) from plus_poll_ans'; $count = mysql_query($count); $count = mysql_fetch_array($count); $total_count = $count['count(ans_id)']; echo "<font size='1' face='Verdana' color='#000000'>".$total_count." votes</font>"; echo "</td></tr>"; echo "</table>"; echo "</font>"; if ($vote!='no') { $to = 'person1@example.com, person2@example.com'; $subject = 'Someone just made a declaration of faith'; $message = "Someone from the ip address ".$s_id; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: Vote Detector <website@example.com>'. "\r\n"; if ($name!='') { $message = $message." with the name ".$name; } if ($email!='') { $message = $message." with email ".$email; } $message = $message." voted "."yes<br/>"; $message = $message."total number of people who declared their faith: ".$total_count." people<br/>"; $message = $message."with a total of ".$total_opt[0]." people saying yes"; $message = $message." and a total of ".$total_opt[1]." people saying no<br/>"; mail($to, $subject, $message, $headers); } ?> Similar Tutorialswhat i want is to upload my informations to database when i press the submit button. but if any field is empty it should show a text that all fields are required but in the same page(up or down to the form). However with this code my database is not working>informations are not send to the database. why?Any sggesstions? Code: [Select] <?php // Start a session for error reporting session_start(); //Connect to database require("includes/connect_to_mysql.php"); //check if the button is pressed if(isset($_POST['submit'])){ // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { // This is an array that holds all the valid image MIME types $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // This variable is the path to the image folder where all the images are going to be stored // Note that there is a trailing forward slash $TARGET_PATH = "upload_form_images/"; // Get our POSTed variables $name = $_POST['name']; $surname = $_POST['surname']; $email = $_POST['email']; $city = $_POST['city']; $details = $_POST['details']; $price = $_POST['price']; $image = $_FILES['image']; // Sanitize our inputs $name = mysql_real_escape_string($name); $surname = mysql_real_escape_string($surname); $email = mysql_real_escape_string($email); $city = mysql_real_escape_string($city); $details = mysql_real_escape_string($details); $price = mysql_real_escape_string($price); $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved do // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $name == "" || $surname == "" || $email == "" || $city == "" || $details == "" || $price == ""|| $image['name'] == "" ) { $_SESSION['error'] = "Te gjithe fushat duhet plotesuar"; echo "Te gjithe fushat duhet plotesuar"; header("Location: upload_form.php"); exit; } // Check to make sure that our file is actually an image // You check the file type instead of the extension because the extension can easily be faked if (!is_valid_type($image)) { $_SESSION['error'] = "Fotografite duhet te jene te formateve jpg, jpeg, bmp, gif, ose png"; header("Location: upload_form.php"); exit; } // Here we check to see if a file with that name already exists // You could get past filename problems by appending a timestamp to the filename and then continuing if (file_exists($TARGET_PATH)) { $_SESSION['error'] = "Ju lutem nderroni emrin e fotos."; header("Location: upload_form.php"); exit; } /* // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM upload_form WHERE name='$name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { $_SESSION['error'] = 'Ju lutem nderroni emrin sepse egziston ne databaze'; header("Location: upload_form.php"); exit(); } */ // Lets attempt to move the file from its temporary directory to its new home if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { // NOTE: This is where a lot of people make mistakes. // We are *not* putting the image into the database; we are putting a reference to the file's location on the server $sql = "insert into people (name, surname, email, city, details, price, filename) values ('$name', '$surname', '$email', '$city', '$details', '$price', '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Futja e te dhenave ne databaze DESHTOI: " . mysql_error()); echo "Shtimi i te dhenave u krye me SUKSES"; exit; } else { // A common cause of file moving failures is because of bad permissions on the directory attempting to be written to // Make sure you chmod the directory to be writeable $_SESSION['error'] = "Shtimi i te dhenave NUK u krye me Sukses. Ju lutem provoni perseri"; header("Location: upload_form.php"); 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>Qiraja.com</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <!--[if lte IE 6]><link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" /><![endif]--> <!--[if IE]><style type="text/css" media="screen"> #navigation ul li a em { top:32px; } </style><![endif]--> </head> <body> <!-- Header --> <div id="header"> <div class="shell"> <!-- Logo --> <h1 id="logo"><a href="#">Company Name</a></h1> <!-- End Logo --> <!-- Navigation --> <div id="navigation"> <ul> <li><a href="#">Prishtine<span><em></em></span></a></li> <li><a href="#">Prizren<span><em></em></span></a></li> <li><a href="#">Ferizaj<span><em></em></span></a></li> <li><a href="#">Peje<span><em></em></span></a></li> <li><a href="#">Mitrovice<span><em></em></span></a></li> <li><a href="#">Gjilan<span><em></em></span></a></li> <li class="last"><a href="#">Gjakove<span><em></em></span></a></li> </ul> </div> </div> </div> <div id="slider"> <div class="shell"> <!-- Slides --> <div class="slides"> <ul> <!-- Slide --> <li> <form action="upload_form.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="center">Name</td> <td width="80%"><label> <input name="name" type="text" id="name" size="25" /> </label></td> </tr> <tr> <td align="center">Surname</td> <td><label> <input name="surname" type="text" id="surname" size="25" /> </label></td> </tr> <tr> <td align="center">Email</td> <td><label> <input name="email" type="text" id="email" size="25" /> </label></td> </tr> <tr> <td align="center">City</td> <td><select name="city" id="city"> <option value=""></option> <option value="Prishtine">Prishtine</option> <option value="Prizren">Prizren</option> <option value="Ferizaj">Ferizaj</option> <option value="Peje">Peje</option> <option value="Mitrovice">Mitrovice</option> <option value="Gjilan">Gjilan</option> <option value="Gjakove">Gjakove</option> </select></td> </tr> <tr> <td align="center">Cmimi</td> <td><label> <input name="price" type="text" id="price" size="10" /> € </label></td> </tr> <tr> <td align="center">Fotografite</td> <td><label> <input type="file" name="image" id="image" /> </label></td> </tr> <tr> <td> </td> <td align="right"><label> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="submit" name="submit" id="submit" value="Shto te dhenat" /> </label></td> </tr> </table> </form> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Shtepine</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Apartmanin</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> </ul> </div> <!-- End Slides --> </div> </div> <!-- End Slider --> <!-- Slider Nav --> <div id="slider-navigation"> <div class="shell"> <ul> <li><a href="index.php" class="active">Kthehu ne fillim<strong>Home</strong><em class="ico1"></em></a></li> <li><a href="upload_form.php">Shto<strong>Upload</strong><em class="ico2"></em></a></li> <li class="last"><a href="contact_form.php">Kontakti<strong>Contact</strong><em class="ico3"></em></a></li> </ul> </div> </div> <!-- End Slider Nav --> <!-- Main --> <div id="main"> <div class="shell"> <!-- Cols --> <div class="cols"> <div class="cl"> </div> <!-- Col --> <div class="col"> <h3>Sed Turpis sem</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero.<br /><a href="#" class="more">read more</a></p> <p>Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col col-last"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <div class="cl"> </div> </div> <!-- End Cols --> </div> </div> </body> </html> I'm getting a '500 Internal Server' and 'Premature end of script headers..' errors in the process of uploading a file. This occurs consistently with files > 2MB but also (very occasionally) w/ smaller files. The target directories are beneath the web root folder, so I don't think it's a permissions issue. I've set the following in my php5.ini: post_max_size = 8M, upload_max_filesize = 8M max_input_time = 360 max_execution_time = 360 Trace code/logging reveals that the error occurs even before my upload code is entered (which uses (move_uploaded_file()). So what would cause that? Any suggestions on how to debug this are very much appreciated! Hello there, Thank you for taking the time to visit my thread. I've been brainstorming for the past few days trying to establish the best method of a content management system. I'm curious since you are all highly advanced PHP coders what you think the best method of content management is I would like it to be presented in the URL in the following method: file.php?v=example So please share your ideas remember there is never a stupid suggestion I want to hear all your possibilities please! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=308872.0 hi Guys..............i am final year student and i need to submit a project that should me medium to large size and i want to build it on PHP so it would be very kind if you can kindly suggest me topics for the same however there is just one restriction the process that i cannot build anything like management systems or social networking websites the idea should be new and catchy and ya one more thing no e-com websites as well.....................looking ahead for your advice..................thank you. This is what I am using and it returns the entire schedule for the whole league... if ($display == "schedule") { $schedule = $ffn->getSchedule(); echo '<h4>Season Schedule</h4>'; echo '<p>Season: ', $schedule->Season, '</p>'; foreach($schedule->Games AS $game) { echo '<p>'; echo 'Week: ', $game->Week, ' ', $game->AwayTeam, ' at ', $game->HomeTeam, ' on ', date("M j, Y", strtotime($game->GameDate)), ' at ', $game->GameTime, ' ', $schedule->Timezone; echo '</p>'; } } BUT what I would like to do is search the info and only post info for one team... I have tried this... if ($display == "schedule") { $schedule = $ffn->getSchedule(); echo '<h4>Season Schedule</h4>'; echo '<p>Season: ', $schedule->Season, '</p>'; foreach($schedule->Games AS $game) if (AwayTeam == 'DAL") { echo '<p>'; echo 'Week: ', $game->Week, ' ', $game->AwayTeam, ' at ', $game->HomeTeam, ' on ', date("M j, Y", strtotime($game->GameDate)), ' at ', $game->GameTime, ' ', $schedule->Timezone; echo '</p>'; } } ELSE IF (HomeTeam == 'DAL') if ($display == "schedule") { $schedule = $ffn->getSchedule(); echo '<h4>Season Schedule</h4>'; echo '<p>Season: ', $schedule->Season, '</p>'; foreach($schedule->Games AS $game) { echo '<p>'; echo 'Week: ', $game->Week, ' ', $game->AwayTeam, ' at ', $game->HomeTeam, ' on ', date("M j, Y", strtotime($game->GameDate)), ' at ', $game->GameTime, ' ', $schedule->Timezone; echo '</p>'; } } Else echo "No Games Scheduled" Problem is it's not working... how can I just pull the info for DAL and only display that info. The info is coming from an XML file... Thanks in Advance! i have made my own website suggestion box but when i start typing in on my websites search box google chrome automatically suggests other words and you can't see underneath. I don't want this to happen to other people viewing my website. Is there any sort of code i an put on my website to stop this? How to do #3 by a PHP page instead? mainly so that there wouldn't be a need to export the sql after doing #2 then import it into the online phpmyadmin(#3) #1. Convert database from foxpro to sql #2. Change some fields in the sql table #3. Upload to phpmyadmin Is it possible to create a code to export from the server and then import the sql online? like by making use of mysql_fetch_array() and insert into I'm in the process of making a PHP/MYSQL game and I'm trying to figure out the best way to set the database up specifically to deal with items. All day I have been wrestling with how to do this. How do I link items to players? How do I keep track of who has what items? I know this question isn't at all specific sorry for that, it's hard to explain exactly what I mean thought text. Thanks Hello, This whole time working online and what not, I always end up using PayPal as a payment method. How to I use credit cards as a payment method ... for free? Can someone please explain the process of payment via credit cards Thanks Hi guys. I haven't been for a while in this great community. I'm starting to develop a PHP-based forum software that I'm planning to release as Open Source locally (in my country, Albania). I've got a few developers in the team to help me on the core and features. But I wanted to ask for a few suggestions on some specific features. I have a few ideas on them, but you may have better options. 1. Forums and topics marked as "read" or "unread" are a nice feature that gives you in a glimpse what has happened. The problem is that I have no good idea on how to implement it. My first thought was to store an array in a cookie with the threads read in the last 10 days (so it doesn't become overloaded) and check those dates with the updated posts. Any idea that could work better? 2. I've never handled an "update feature". The idea is to offer an update installation when I will release the software and maintain it. Any idea how to design such a feature? 3. Any suggestion on searching (FULL TEXT SEARCH) and caching (DB and Template)? Hope it's not too much a request and you guys can give a few suggestions. I could really use some advise and ideas on PHP caching. Specifically I'm working on a CMS application and after its completed I realized there is an opportunity to increase performance if some of the pages are cached. And the terms I'm using for search are taking too long to sift through I thonk what I'm looking for could be like a CGI script, but I don't have any experience with that right now. Another idea is to wrap my 'public php' page with a check for an existing cached file, else run the query. And add, somewhere in my existing 'admin php' page, a write to file scriptie to create the cache file. Or something else entirely. I don't know yet. I'd like to read some explanations of projects and scripts that either create a 'push CMS' application, or maybe a 'pull CMS' where the parameters for the cache are not time-based (expiration) but file based (file exist?). Or something else... Kudos and huzz-zaa's for the dude who can put words to my dribble. Hello,
I went through the forum, its geat but I think missing one feature,
There should be a forum about having general conversations and if someone wanted to talk about taking suggestions to help him/her across the world of programming, that would be very great.
Thanks.
Hello all, I'm looking for some advice on a problem. I have a very basic web page containing three section, the header, the content and the footer in that order. What I would like is the header and footer always on the page and only the content section change by means of links in a navigation bar. I've looked into iframes, php include, javascript and something called Ajax and must say I'm all a bit confused by it all. Which would be most advisable and how would I excecute it. My pages are as follows. Home page is. index.php Pages I would like to show in the content Div. about.php contact.php home.php If you need any more information, please let me know. Thank you in advance for your help. suggestions on how to write this code better I have a form that has 2 textboxes in it. The php listed below...confirms that the passwords match, confirms that there are at least 6 characters in in, confirms that there is at least 1 number. I am doing mostly if statements with it, but I was wondering if there was a better way to write. Code: [Select] <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" method="post" action="<?PHP $_SERVER['PHP_SELF'] ?>"> <table width="100%" border="1"> <tr> <th scope="row"> <strong>New password: </strong> <input type="password" maxlength="15" name="password"></th> <th scope="row"> <strong>New password confirmed: </strong> <input type="password" maxlength="15" name="confirm_password"></th> <th scope="row"><input type="submit" name="update" value="Update Password" /></th> </tr> </table> </form> <?PHP //verify that the update button is pressed if (isset($_POST['update'])) { //verify that the passwords match if($_POST['password'] == $_POST['confirm_password']) { echo "passwords match"; echo "<br>"; } //verify that the password and password confirmation was entered elseif ((isset($_POST['password'])) && ($_POST['confirm_password'])) { echo "Password and confirm password set"; echo "<br>"; } //verify that the # of characters was entered elseif (strlen($_POST['password'])<6) { $num_char=strlen($_POST['password']); echo "Please enter more characters"; echo "<br>"; } //find out if number exsist if (strlen($_POST['password'])>5) { $subject = $_POST['password']; preg_match_all('/[0-9]/', $subject, $matches); $count = count($matches[0]); //echo $count; if ($count <=1) echo "Please enter in at least 1 number you currently have: " .$count; }//close of verification of both boxes entered }//close of $_POST ?> </body> </html> I know there are many open source shopping carts available, but I wanted to write my own to gain a better understanding of the coding practices involved. Below is my almost finished shopping cart class for an e-commerce website I am building. I want to be able to handle all purchasing capability from the Cart class as you can see from what I have below. I was wondering if anyone can see any areas for improvement before I go implementing it into my website. Any help is appreciated and thank you in advance. Code: [Select] <?php /** * Cart class handles all shopping cart activity. * * This class also handles saving order information for each purchase. * * After each order is complete be sure to call the Product::inventoryCheck() * to notify administrator of low quantities. */ class Cart { public $db; private $_cartName; /** * Creates a new shopping cart if one does not exist already. * Initiates the database connection for future use. */ public function __construct($cartName = 'cart') { $this->_cartName = $cartName; if (!isset($_SESSION[$this->_cartName])) { $_SESSION[$this->_cartName]; } $this->db = Database::getInstance(); } /** * Returns all items in the shopping cart and their information. * I want to be able to return the quantity as well. * I will take this information and use it to display the shopping cart to the customer. */ public function getCartItems() { try { foreach ($_SESSION[$this->_cartName][$id] as $productId => $quantity) { $stmt = $this->db->prepare( "SELECT product_id, product_name, product_thumb, product_price, product_discount FROM product WHERE product_id = ?"); $stmt->setFetchMode(PDO::FETCH_ASSOC); $stmt->execute(array($productId)); return array($stmt->fetchAll(), $quantity); } } catch (Exception $e) { return FALSE; } } /** * Adds an item to the shopping cart. * Also used to change quantities of items already in shopping cart. * @param $id - integer * @param $quantity - integer ($quantity comes from a drop down menu populated by the database) */ public function addItem($id, $quantity) { try { $_SESSION[$this->_cartName][$id] = $quantity; } catch (Exception $e) { return FALSE; } } /** * Deletes an item from the shopping cart. * @param $id - integer */ public function deleteItem($id) { try { unset($_SESSION[$this->_cartName][$id]); } catch (Exception $e) { return FALSE; } } /** * Empties all contents out of the shopping cart. * Call this function when all purchase activity is complete so the user has a new cart to start with. */ public function clearCart() { try { unset($_SESSION[$this->_cartName]); } catch (Exception $e) { return FALSE; } } /** * Saves a purchase after it is successful. * @param $subTotal - integer * @param $tax - integer * @param $discount - integer * @param $total - integer */ public function savePurchase($subTotal, $tax, $discount, $total) { try { $stmt = $this->db->prepare( "INSERT INTO purchase (purchase_customer_id, purchase_timestamp, purchase_ip, purchase_subtotal, purchase_tax, purchase_discount, purchase_total, purchase_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute(array($_SESSION['customer_id'], NOW(), $_SERVER['REMOTE_ADDR'], $subTotal, $tax, $discount, $total)); return $purchaseId; } catch (Exception $e) { return FALSE; } } /** * Saves each item from a purchase. * Updates product quantities in product table. * @param $purchaseId - integer */ public function saveCartItems($purchaseId) { try { foreach ($_SESSION[$this->_cartName][$id] as $productId => $quantity) { $stmt = $this->db->prepare( "INSERT INTO purchase_item (purchase_item_product_id, purchase_item_purchase_id, purchase_item_quantity) VALUES (?, ?)"); $stmt->execute(array($productId, $purchaseId, $quantity)); $update = $this->db->prepare( "UPDATE product SET product_quantity = product_quantity - $quantity WHERE product_id = ?"); $update->execute(array($productId)); } } catch (Exception $e) { return FALSE; } } /** * Calculates shipping cost and applies it to the shopping cart. */ public function shipping() { // need to find out pricing structure } /** * Applies a coupon discount if coupon parameters are met * Checks for coupon code validity from the coupon table * @param $couponCode - varchar */ public function useCoupon($couponCode, $cartPrice) { try { $stmt = $this->db->prepare( "SELECT coupon_amount, coupon_minimum_price FROM coupon WHERE coupon_code = ? AND coupon_active = 'Yes'"); $stmt->setFetchMode(PDO::FETCH_ASSOC); $stmt->execute(array($couponCode)); $stmt->fetch(); // make sure there is a coupon available that matches customer input if (count($stmt) != 1) { return FALSE; } // chcek if the current cart price (minus taxes and shipping) is greater than coupon minimum price if ($cartPrice < $stmt['coupon_minimum_price']) { return FALSE; } // this will go in the coupon field in the cart view return $stmt['coupon_amount']; } catch (Exception $e) { return FALSE; } } } This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330946.0 I have a database table of product titles. For each product, I want to link 10-20 similar products, ordered by relevance. For example: db.products ID Title 1 White Paint, Quick Dry 2 Yellow light bulb >50000 .... db.product_similarity ID PID simular_to_PID rank 1 1 22 1 2 1 322 2 Anybody have any suggestions about how I could go about this? The main concern is quality/relevance and accuracy. thanks. Hello All, I am building a web based data entry project for my University Recycling Department 1) In the first level the user will enter the number of "rows" that he has to enter it can be any number form 4- 10 . Each row will contain "Vendor Name","Date","Net Recycled Weight" 2) Depending on the number of rows entered by the user I am generating a table structure that has 2.1) A <select> containing vendor names(I am querying for this and then storing the result in an Associative Array and then parsing it for select in every way) 2.2) A text box for the date 2.3) A text box for the Net Recycled Weight ------------------------------------------------ Here is the logic I have implemented so far <html> <head></head> <body> <form name = "form1" method = "post"> <select>HERE THE USER CAN SELECT THE NUMBER OF ROWS HE WANTS TO ENTER</select> <input type = "submit" value = "submit1" name = "submit1"> </form> <body> </html> <?php if(submit1 has been clicked ) { //HERE I AM GENERATING A DYNAMIC FORM BASED ON THE NUMBER OF ROWS COUNT <form name = "form2" method = "post"> echo <table> echo <tr> echo<td>VENDOR</td> echo<td>DATE</td> echo<td>NET RECYCLED WEIGHT</td> echo </tr> for(IT ITERATES TILL I GENERATE THE NUMBER OF ROWS THAT HAS TO BE ENTERED) { I AM GENERATING ROWS HERE } echo <input type = "submit" name = "submit2" value = "submit2"> echo</table> </form> HOW CAN I ACCESS THE POST METHOD OF FORM 2 } ?> MY PROBLEM --------------- I WANT TO KNOW THE FOLLOWING 1) It this the correct way to do it 2) how can I access the data entered in each dynamic row as I have to validate it and then enter the data in MySql 3) I am not sure how I will access the submit button event of the dynamically generated form I hope I can get some help Thanks, Marisha Heya! I've coded a small php template parser, so templates can be easily parsed, and the variables within the templates are like {variable_name} e.g. Code: [Select] <title>{title}</title> Can you suggest me possible if/else statement syntax? I've thought of doing something like: {if {logged_in}: TRUE} Your logged in... {else} Your not... {/if} and... {if {logged_in}: TRUE} Your logged in... {/if} The above demonstrates basic if/else template syntax (it checks if the variable logged_in == true), but since I'm more of a coder then designer, was wondering if I can have your input (so designers can easily understand the syntax without knowledge of server-side coding). Cheers! |