PHP - Adding More Than On Item To Cart At Time??
I have am working on a shopping cart, for coupong buying. Here it only allows me to add one Item or One deal ata time into shopping cart. How can I change this code to accept more than one deal at a time before checking out. Code: [Select] { // add to cart /* $cart = unserialize(JFactory::getSession()->get('cart')); if (empty($cart)) $cart = new Cart(); */ // We only allow 1 item per cart from now one... $cart = new Cart(); $cart->addItem($deal); JFactory::getSession()->set('cart', serialize($cart)); $dealName = $deal->name; $buy4friend = $_GET['buy4friend']; $cartItemCount = $cart->getItem($dealId)->getCount(); if($buy4friend == 1) { $msg = $dealName . " :::<b> ". JText::_("DEAL_ADD_TO_CART_MESUN"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=viewCart&buy4friend=1", false); JFactory::getApplication()->redirect($link, $msg); }else{ $msg = $dealName . " ". JText::_( "DEAL_ADD_TO_CART"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=viewCart&buy4friend=0", false); JFactory::getApplication()->redirect($link, $msg); } Similar TutorialsHey again, Still on the same project but now doing the cart page. I've been bringing my skills up to date a lot doing this project, however, having said that I now can't figure out why my cart is not adding the items to the cart, i've checked the post data and the quantity is set to 1. Would really appreciate someone having a look at it and hopefully can see what i'm missing. you can see what it should look like (well so far lol) at here in my sandbox site. thanks again. (p.s. The parts are all over the place on the page, so thought better put whole page, sorry if shouldn't have done that) <?php // Initialize the session session_start(); // Include config file require_once "dbcontroller.php"; $db_handle = new DBController(); if(!empty($_GET["action"])) { switch($_GET["action"]) { case "add": if(!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery("SELECT * FROM products WHERE product_code='" . $_GET["product_code"] . "'"); $itemArray = array($productByCode[0]["product_code"]=>array('product_name'=>$productByCode[0]["product_name"], 'product_code'=>$productByCode[0]["product_code"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"], 'image'=>$productByCode[0]["img1"])); if(!empty($_SESSION["cart_item"])) { if(in_array($productByCode[0]["product_code"],array_keys($_SESSION["cart_item"]))) { foreach($_SESSION["cart_item"] as $k => $v) { if($productByCode[0]["product_code"] == $k) { if(empty($_SESSION["cart_item"][$k]["quantity"])) { $_SESSION["cart_item"][$k]["quantity"] = 0; } $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"]; } } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } break; case "remove": if(!empty($_SESSION["cart_item"])) { foreach($_SESSION["cart_item"] as $k => $v) { if($_GET["product_code"] == $k) unset($_SESSION["cart_item"][$k]); if(empty($_SESSION["cart_item"])) unset($_SESSION["cart_item"]); } } break; case "empty": unset($_SESSION["cart_item"]); break; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>LeaversHoodies.ie</title> <!-- Bootstrap --> <link href="css/bootstrap-4.4.1.css" rel="stylesheet"> <link href="css/accordian.css" rel="stylesheet"> </head> <body> <?php include 'header_student.php'; ?> <br /> <?php $school_page = "ravenswell"; $sql = "SELECT * FROM schools WHERE school_page = '$school_page'"; if($result = mysqli_query($conn, $sql)) while($row = mysqli_fetch_array($result)) { ?> <h3 class="text-center">Student Ordering Page For</h3> <h2 class="text-center" style="text-transform:uppercase;"><?php echo $row['school_name']; ?></h2> <hr style="width: 50%; text-align:center; border: 2px solid #00aeef; border-radius: 5px; margin: 0 auto;"> <br /> <div class="container"> <div class="row"> <div class="col"> <?php $path = "images/schools/"; $file = $row["logo"]; if(!empty($row['logo'])) { echo '<img src="'.$path.$file.'" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } else { echo '<img src="images/schools/140x140.gif" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } ?></div> <div class="col-6"> <h5>These are the garments your school has choosen :</h5><br /> <?php $school_id = $row["school_id"]; } var_dump($_SESSION); var_dump($_POST); $product_array = $db_handle->runQuery("SELECT * FROM choices INNER JOIN products USING (product_code) INNER JOIN colours USING (colour_id) WHERE school_id = '$school_id'"); if (!empty($product_array)) { foreach($product_array as $key=>$value){ ?> <div class="container"> <div class="row"> <div class="col-5" style="text-align:left;"> <img src="images/products/<?php echo $product_array[$key]["img1"]; ?>" alt="<?php echo $product_array[$key]["product_code"]; ?>" style="position:relative; top:0; width:200px; display:block;"> </div> <div class="col-7"> <h5><?php echo $product_array[$key]["product_name"]; ?></h5><p> in <?php echo $product_array[$key]["colour_name"]; ?></p> <p style="font-size:12px;"><?php echo $product_array[$key]["description"]; ?></p> <?php $comment = $product_array[$key]["comment"]; if (empty($comment)) { echo ""; } else { ?> <p style="font-size:12px;"><b>A note from your teacher:</b> <br /> <?php echo $product_array[$key]["comment"]; ?></p> <?php }; ?> <form action="student_order.php?schoolname=<?php echo $school_page; ?>?action=add&product_code=<?php echo $product_array[$key]["product_code"]; ?>" method="post"> <?php $product = $product_array[$key]["product_code"]; ?> Please select your size : <select id="size" name="size"> <?php $sql1 = "SELECT DISTINCT * FROM sizes WHERE product_code = '$product'"; if($result1 = mysqli_query($conn, $sql1)) while($row3 = mysqli_fetch_array($result1)){ echo "<option value='" . $row3['size'] . "'>" . $row3['size'] . "</option>"; } else { echo "nothing to see here"; } ?> </select> <br /><br /> <div class="number">How many do you want: <input type="number" style="font-size:12px;" id="quantity" name="quantity" value="1" min="1" max="5"><br /> Price : <?php echo "€".$product_array[$key]["price"]; ?> </div> <input type="hidden" id="product_code" value="<?php echo $product; ?>"><br /> <input type="submit" style="font-size:12px;" value="Add to Order" class="btnAddAction"> </form> </div> </div> <br /><hr style="width: 90%; text-align:center; border: 1px solid #00aeef; border-radius: 5px; margin: 0 auto;"><br /> </div> <?php } } else { echo "No Schools by that name registered."; } ?> </div> <div class="col-3"> <div style="border: 1px solid #d3d3d3; padding: 10px; border-radius: 5px; margin-top:30px;"> Your Order: </div> </div> </div> <div class="txt-heading">Shopping Cart</div> <a id="btnEmpty" href="student_order.php?schoolname=<?php echo $school_page; ?>?action=empty">Empty Cart</a> <?php if(isset($_SESSION["cart_item"])){ $total_quantity = 0; $total_price = 0; ?> <table class="tbl-cart" cellpadding="10" cellspacing="1"> <tbody> <tr> <th style="text-align:left;">Name</th> <th style="text-align:left;">Code</th> <th style="text-align:right;" width="5%">Quantity</th> <th style="text-align:right;" width="10%">Unit Price</th> <th style="text-align:right;" width="10%">Price</th> <th style="text-align:center;" width="5%">Remove</th> </tr> <?php foreach ($_SESSION["cart_item"] as $item){ $item_price = $item["quantity"]*$item["price"]; ?> <tr> <td><img src="images/products/<?php echo $item["img1"]; ?>" class="cart-item-image" /><?php echo $item["product_name"]; ?></td> <td><?php echo $item["product_code"]; ?></td> <td style="text-align:right;"><?php echo $item["quantity"]; ?></td> <td style="text-align:right;"><?php echo "$ ".$item["price"]; ?></td> <td style="text-align:right;"><?php echo "$ ". number_format($item_price,2); ?></td> <td style="text-align:center;"><a href="student_order.php?schoolname=<?php echo $school_page; ?>?action=remove&product_code=<?php echo $item["product_code"]; ?>" class="btnRemoveAction"><img src="icon-delete.png" alt="Remove Item" /></a></td> </tr> <?php $total_quantity += $item["quantity"]; $total_price += ($item["price"]*$item["quantity"]); } ?> <tr> <td colspan="2" align="right">Total:</td> <td align="right"><?php echo $total_quantity; ?></td> <td align="right" colspan="2"><strong><?php echo "$ ".number_format($total_price, 2); ?></strong></td> <td></td> </tr> </tbody> </table> <?php } else { ?> <div class="no-records">Your Cart is Empty</div> <?php } ?> </div> </div> <br /><br /> <?php include 'footer_student.php'; ?> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-3.4.1.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/popper.min.js"></script> <script src="js/bootstrap-4.4.1.js"></script> </body> </html>
Hi, I'm hoping someone can lead me in the right direction here. I'm creating a simple shopping cart that I will later pass on to Paypal for payment but my problem is, it won't add the items to my shopping cart when I click add to cart. My products are on different pages and I'm not sure if that is going to matter. When I click "add to cart" nothing gets added and it says my cart is empty. I have two tables with the following columns: 1. products: productId productName productDesc productPrice link (for dynamically creating the page links on the main product page) 2. productscents scentId scentName scentDesc Here is the add code that is in my first products page (Elite Hand Cream): Code: [Select] <?php if(isset($_GET['action']) && $_GET['action'] == "add") { $id = intval($_GET['id']); $desc=intval($_GET['desc']); if (isset($_SESSION['cart'][$id])) { $_SESSION['cart'][$id]['quantity']++; } else { $sql3 = "SELECT * FROM products WHERE productId=[$id]"; $sql4= "SELECT * FROM productscents WHERE scentId=[$desc]"; $query3 = mysql_query($sql3); $query4 = mysql_query($sql4); if(mysql_num_rows($query3) != 0) { $row3 = mysql_fetch_array($query3); $row4 = mysql_fetch_array($query4); $_SESSION['cart'][$row3['productId']] = array("quantity" => 1, "price" => $row3['productPrice'], "desc" => $row4['scentId']); } } } ?> Here is code I have for the $_SESSION: Code: [Select] <?php if(isset($_SESSION['cart'])) { $sql5= "SELECT * FROM products,productscents WHERE productId IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql5 .= $id . ","; } $sql5 = substr($sql,0,-1) . ") ORDER BY productId, scentId ASC"; $query = mysql_query($sql5); if(!empty($query)) { while($row = mysql_fetch_assoc($query)) { ?> <?php echo $row['productName'];?><?php $_SESSION['cart'][$row['productId']]['quantity'];?> <?php } } else { echo "You need to add an item to your cart";} } Here is the code that I have for the "add to cart" and "view cart": Code: [Select] <a href=#&action=add&id=<?php echo $prodId;?>&desc=<?php echo $scent_id[$y];?>>Add to Cart</a><br><a href="cart.php">View Cart</a> This grabs the correct product Id and scent Id which I want and no errors are being displayed on the page. I'm not sure where to begin with this. LOL. I'm new to PHP and I used a tutorial to help with the code. Any help would be greatly appreciated. Hi, I am making a shopping cart and I have a problem. My code to remove the items from the cart works except for the first added item; I can delete all but that one.
<form class="col-md-12" method="POST" action="" id="formremove"> <input type="hidden" name="id_prod" value="<?php echo $row['id_producto'] ?>"> <input type="submit" name="btn-remove" class="btn btn-info btn-sm" id="remove" value="X"> </form> And this is the php
if ($_POST['btn-remove']) { $id_user=$_SESSION['id_user']; $id_prod = $_POST['id_prod']; $SQLREM = "DELETE FROM `carrito` WHERE id_user='$id_user' and id_producto='$id_prod';"; if (mysqli_query($conn, $SQLREM)) { echo '<script> alert("Ok"); window.location="/CBA/WAUW/cart.php"</script>'; } else { echo '<script> alert("Error"); window.location="/CBA/WAUW/cart.php"</script>'; }; } The connection to the database works fine; as I said before, it deletes everything but the first item added. I would be very grateful for any help.
Is it possible to add more then one thing in a link? so i can $_GET more then one thing from a link signup.php?state=1?name=sam i tried that and a few other things and it didnt work. OK, so I have a form which submits the id of an item on a shopping site as well as the size selected by the customer. Size S/M is 1 Size M/L is 2 To get what has been submitted when they click "Add To Basket" i have this code: Code: [Select] $sizechoice = $_POST['sizechoice']; $basket = $_SESSION['basket']; $action = $_GET['action']; switch ($action) { case 'add': if ($basket) { $basket .= ','.$_GET['id'].'-'.$sizechoice; } else { $basket = $_GET['id']; } } I used to have it like that, but minus $sizechoice, so the basket was just ids like 1,5,3,2. Now each id is accompanied by a size choice, so it would be 1-1,5-1,3-2,2-1 for example. How can I later separate the id from the size again using the dash? Thanks, Jack Hi there, I'm creating a shopping cart and to work out postage cost I need to add all the items weights together. The weight of each item is in the database. I currently have this code: Code: [Select] $basket = $_SESSION['basket']; if ($basket) { $items = explode(',',$basket); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } foreach ($contents as $id=>$qty) { $sql = "SELECT * FROM store WHERE id LIKE '$id' AND live LIKE '0'"; $result = mysql_query($sql); while ($rows = mysql_fetch_array($result)) { extract($row); so to work out each item's weight I can do $rows['weight'] * $qty. but how could i add all the item's weight together? i hope that makes some sense. thanks, jack Hi All, not sure if this is a php Q but maybe someone has experience with this. I use a form for people to add an item to the bulletin board. Sometimes the loading of the page takes very long and people think it didn't work so they click reload and post the item twice. I thought of adding a loading.gif so people know they have to wait. Anyone know how and where to put that in? Code: [Select] <?PHP if(isset($_POST['submit'])) { if ($_POST['type']<>"") { $poster_id = $_SESSION['id']; $ID=$_GET['ID']; $short=$_POST['short']; $location=$_POST['location']; if(isset($_POST['type'])) { $type=$_POST['type']; } $starthour=$_POST['starthour']; $startmin=$_POST['startmin']; $endhour=$_POST['endhour']; $endmin=$_POST['endmin']; $reminders=$_POST['reminders']; $reminders=addslashes($reminders); if(isset($_POST['view'])) { $view=$_POST['view']; } if(isset($_POST['val'])) { $val=$_POST['val']; } $sql = mysql_query("SELECT * from bl_calender where dateclass='$ID' AND viewable='1'"); $numrows = mysql_num_rows($sql); // if the event exists then we want to edit it if ($numrows > 0){ // only the owner can edit an event while($row = mysql_fetch_array($sql)){ if($row['poster_id'] == $logOptions_id || $account_type == 'c' ){ $editcal="update bl_calender set datecotent='$reminders', location='$location', type='$type', starthour='$starthour', startmin='$startmin', endhour='$endhour', endmin='$endmin', short='$short', viewable='$view' where dateclass='$ID'"; mysql_query($editcal) or die("Could not edit calendar"); $msgToUser = '<br /><br /><font color="#FF0000">Your event has been updated. Close this window.</font><p></p>'; include_once 'msgToUser2.php'; } else { // you are not the owner $msgToUser = '<br /><br /><font color="#FF0000">Sorry but only the owner can change the event details.<br> Close this window.</font><p></p>'; include_once 'msgToUser2.php'; } } } else { // it's a new event we want to add $createevent="Insert into bl_calender (poster_id, dateclass, starthour, startmin, endhour, endmin, location, type, short, datecotent, viewable ) values ('$poster_id', '$ID', '$starthour', '$startmin', '$endhour', '$endmin', '$location', '$type', '$short', '$reminders', '1')"; mysql_query($createevent) or die(mysql_error()); $sql2 = mysql_query("SELECT * FROM myMembers WHERE notification_calendar='1'"); // query the members who want an email $numrows = mysql_num_rows($sql2); if ($numrows > 0){ while($row = mysql_fetch_array($sql2)){ if($row['email'] =="") { $to = $row['email_work']; } else { $to = $row['email']; } $your_firstname = $row['firstname']; $your_lastname = $row['lastname']; // send an email to everyone who wants it $webmaster = "KAI-DEFAT@minbuza.nl"; $headers = "From: MAAC Webmaster<$webmaster>"; $subject = "A new message has been posted in the MAAC Calendar."; $message = "Hello $your_firstname $your_lastname, a new event has been posted in the MAAC Calendar.\n"; $message .= "Goto the MAAC website to get the details.\n"; $message .= "Click here to view the Calendar $dyn_www/Web_Intersect/calen.php\n"; // send email mail($to, $subject, $message, $headers); } } } $msgToUser = '<br /><br /><font color="#FF0000">Your event has been created, Close this window.</font><p></p>'; include_once 'msgToUser2.php'; } ?> did some searching on the internet and didnt find much. i have created an online classifieds website and want all created listings to expire and delete after a certain amount of days. honestly i have no idea where to start with this implementation. cookies were the only thing that even crossed my mind... any ideas? btw each listing is stored in a table called ob_listings This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358003.0 Hi all I have a php form as follows: <form action="basket.php?action=add&id=1&qty=1" method="post" name="buy-product"> <input name="initial_1" id="initial_1" type="text" size="8" maxlength="1" /> <input name="initial_2" id="initial_2" type="text" size="8" maxlength="1" /> <input name="initial_3" id="initial_3" type="text" size="8" maxlength="1" /> <input name="send" type="submit" class="contact-form-button" id="send" value="Submit" /> Basically I need to add the three initials into a session so that they can be shown in the shopping cart next to the product. How do I add the initials to the session and how do I output them to the shopping cart? At the start of my basket.php script I have: $cart = $_SESSION['cart']; $action = $_GET['action']; $id = $_GET['id']; $qty = $_GET['qty']; $initial_1 = $_POST['initial_1']; $initial_2 = $_POST['initial_2']; $initial_3 = $_POST['initial_3']; I now need to create a table with the cart showing item, price and initials. Cheers Pete. Hi Guys I'm building a shopping cart based on the http://www.phpwebcommerce.com/ free tutorial. I'm getting stuck on adding sizes to the product options. what I need: Mens - available in Medium Large and XLarge Womens - available in Small Medium and Large Baby - available in 6, 12, 18 and 24 months I've created arrays to hold the sizing options: Code: [Select] $catAlias = (isset($_GET['a']) && $_GET['a'] != '') ? $_GET['a'] : 0; $product = getProductDetail($pdId, $catId, $catAlias); // populate the arrays $size_m = array("medium", "large", "x-large"); $size_w = array("small", "medium", "large"); $size_b = array("6 months", "12 months", "18 months", "24 months"); // create dropdown function createDropdown($arr, $frm) { echo '<select name="'.$frm.'" id="'.$frm.'"><option value="">Select one</option>'; foreach ($arr as $key => $value) { echo '<option value="'.$value.'">'.$value.'</option>'; } echo '</select>'; } and can call them into a dropdown depending on the department alias Code: [Select] <p>Choose your Size: <?php if ($catAlias == "mens-tees") { createDropdown($size_m, 'frmsize');} elseif ($catAlias == "womens-tees") { createDropdown($size_w, 'frmsize');} elseif ($catAlias == "inkababy") { createDropdown($size_b, 'frmsize');} ?> </p> The resulting HTML looks like this: Code: [Select] <p>Choose your Size: <select name="frmsize" id="frmsize"><option value="">Select one</option><option value="medium">medium</option><option value="large">large</option><option value="x-large">x-large</option></select></p> - so far so good. I'm struggling to find a way to pass the chosen size (frmsize) to the mini-cart and cart pages to store as an order. I've been Googling for days, reading through O'Reilly PHP, MYSQL book and haven't been getting anywhere. The flow is: Choose size click buy now > All detail are pass through getCartcontents function to mini-cart (shown in sidebar) and cart > details then passed through to checkout. Where do I store the chosen size variable for each t-shirt? How do i declare that this one is for product X in mens size or product X in womens size Would really appreciate some advice, I just can't get my head around the concept of where the chosen size goes and how to pass it to the cart(s). Thanks This is the code that I'm using for a shopping cart in order to update the quantity if the same product id is chosen. $cart_items is a two-dimensional session array composed of the id session array and the quantity session array. While looping through $cart_items, I create a temporary array $temp_array so that I can execute some logic on the array without changing the normal output. $temp_array is the $cart_items array without the last items which would be the $_REQUEST id and the $_REQUEST quantity. So the two $_REQUESTs are popped off with array_pop and then the remaining $_SESSIONs are compared to the $_REQUEST id with
$j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) If $j is the key of the item in $temp_array, then the $_REQUEST is unset and the quantities for the item are added together.
There are two problems with this code. First of all the var_dump of the $temp_array is always an empty array but I am expecting to get an array with just the last element popped off. Secondly, foreach($cart_items as $item) { foreach($item["id"] as $key => $val) { foreach($item["quantity"] as $i => $value) { if ($key == $i){ $temp_array = $cart_items; $array = array_pop($temp_array); var_dump($temp_array); if (isset($_REQUEST["element_id_$i"]) && isset($_REQUEST["quantity_$i"])&& isset($value)){ $j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) { echo "<b>SAME PRODUCT ADDED</b>"; $value += $_REQUEST["quantity_$i"]; unset($_REQUEST["element_id_$i"]); }}}}}}
Hi again guys, Right, I have two times being output from a database... The first time is the time something is booked in for (eg: 16:30:00) and the second time is the duration that thing is booked in for (eg an hour and a half - 01:30:00) Now, I want to figure out when that thing will be finished, so using the two examples above, it will be finished at 18:00:00, I've tried a few things with no success Please help Cheers
I have a given date on a webpage, that I'm scraping to insert into a DB. The date is in this format: $date = 'Sun, Feb 9<br />3:00 PM ET': $healthy = array("<br />", " ET", "Sun.", "Mon.", "Tue.", "Wed.", "Thu", "Fri.", "Sat.", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $yummy = array(" ", "2020", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $date = str_replace($healthy, $yummy, $date1); $start = date('Y-m-d H:i:s', strtotime("$date -120 minutes"));
I'm trying to add some minutes ($interval) to any given time, but my results aren't as expected... Code: [Select] <?php $year="2012"; $opentime="09"; $interval="10"; $thedate = "$year:01:01 $opentime:00:00"; $startdate = strtotime($thedate); $date = date("Y-m-d",$startdate); $time = date("g:i a",$startdate); $newtime = strtotime("+$interval", $time); $nexttime = date("g:i a",$newtime); echo $date; echo "<br>"; echo $time; echo "<br>"; echo $nexttime; is returning: 2012-01-01 9:00 am 7:10 pm I was expecting the last to be 9:10 am. Can someone point me in the right direction? Thanks. Ok, I have a variable ($incubation) set as 04:00:00. Then I have another variable ($starttime) set to the current time. Both are printing out fine. But I'm trying to get an $endtime from adding the incubation time to the start time. Code: [Select] $incubation = $row['incubation']; //IM GRABBING THIS TIME FROM THE DATABASE. It prints 04:00:00 $starttime = date("H:i:s"); //prints 16:23:39 $endtime = date("H:i:s", $starttime+$incubation); //prints 20:00:00 when it's suppose to print 20:23:39 I have a script that seems to work well to insert a bookmark into a users database when he/she is logged into the system but I am having a hard time figuring out how I would go about making a work-a-round for having an item selected before being logged in, and inserted after they have logged in or registered. For example, I would like a user to be able to select an Item to add to bookmark whether that user is logged in/registered or not and if they are not, they would be greeted with a login/registration form and after successful login the add bookmark script would be initiated on the item previously selected. What I've got this far: Simple form to add bookmark: <form name="bm_table" action="add_bms.php" method="post"> <input type="text" name="new_url" value="http://" /> <input type="submit" value="Add Bookmark"/> </form> Then I have the add bookmark script: BEGIN php $new_url = $_POST['new_url']; try { check_valid_user(); //cannot get past this part since it ends the script....code below if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } // check URL format if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check URL is valid if (!(@fopen($new_url, 'r'))) { throw new Exception('Not a valid URL.'); } // try to add bm add_bm($new_url); echo 'Bookmark added.'; // get the bookmarks this user has saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } } catch (Exception $e) { echo $e->getMessage(); } END php Checking valid user - the portion I cannot get past in the above script: function check_valid_user() { // see if somebody is logged in and notify them if not if (isset($_SESSION['valid_user'])) { echo "Logged in as ".$_SESSION['valid_user'].".<br />"; } else { // they are not logged in do_html_heading('Problem:'); echo 'You are not logged in.<br />'; do_html_url('login.php', 'Login'); do_html_footer(); exit; } } How would I go about modifying the script so that a user could fill in the form (later it would be a link...obviously they probably wouldn't be filling in a form that is log-in specific - but same concept I think) Thanks in advance for the help! tec4 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306905.0 Hello people. Thank you to everyone who has helped me in the past, this is a great forum full of very helpful members. I am trying to put a pilots logbook application together for the members at microlightforum.com and here is the form that I have put together. What I would like to know is how to code the first "Auto Insert" button so that it takes the time from the variables $takeoff_hr and $takeoff_min and $landing_hr, $landing_min I would like the time difference from taking off to landing putting in the "ws_captain_hrs" box and the "ws_captain_min" box. Therefore if someone took off at 12.30 and landed at 13.50 the "ws_captain_hrs" box should read "1" and the "ws_captain_min" box should read "20" The idea behind this is that it makes it easier for the user to only have to insert take off time and landing time, then click the appropriate button to put the data into the box. 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=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $host = 'localhost'; $usr = "vinny"; $password = 'thepassword'; $db_name = 'logbook'; $date = $_POST['date']; $type = $_POST['type']; $reg_01 = $_POST['reg_01']; $reg_02 = $_POST['reg_02']; $captain = $_POST['captain']; $passenger = $_POST['passenger']; $where_01 = $_POST['where_01']; $where_02 = $_POST['where_02']; $takeoff_hr = $_POST['takeoff_hr']; $takeoff_min = $_POST['takeoff_min']; $landing_hr = $_POST['landing_hr']; $landing_min = $_POST['landing_min']; $ws_captain_hrs = $_POST['ws_captain_hrs']; $ws_captain_min = $_POST['ws_captain_min']; $ws_student_hrs = $_POST['ws_student_hrs']; $ws_student_min = $_POST['ws_student_min']; $three_captain_hrs = $_POST['three_captain_hrs']; $three_captain_min = $_POST['three_captain_min']; $three_student_hrs = $_POST['three_student_hrs']; $three_student_min = $_POST['three_student_min']; $passenger_hrs = $_POST['passenger_hrs']; $passenger_min = $_POST['passenger_min']; $remarks = $_POST['remarks']; $errorstring = ""; // default value of errorstring if(isset($_POST['save_flight'])) { // Validate all the code inputs that are required fields if ($date =="") $errorstring = $errorstring. "Date<br>"; if ($type =="") $errorstring = $errorstring. "Aircraft Type<br>"; if ($reg_01 =="") $errorstring = $errorstring. "Reg Prefix<br>"; if ($reg_02 =="") $errorstring = $errorstring. "Registration Mark<br>"; if ($captain =="") $errorstring = $errorstring. "Captain<br>"; if ($where_01 =="") $errorstring = $errorstring. "Flight From<br>"; if ($where_02 =="") $errorstring = $errorstring. "Flight To<br>"; if ($takeoff_hr =="") $errorstring = $errorstring. "Takeoff Hours<br>"; if ($takeoff_min =="") $errorstring = $errorstring. "Takeoff Minutes<br>"; if ($landing_hr =="") $errorstring = $errorstring. "Landing Hours<br>"; if ($landing_min =="") $errorstring = $errorstring. "Landing Minutes<br>"; // does the errorstring = "nothing"? if ($errorstring !="") echo "You have not put anything in the following fields: <br><br> $errorstring"; //echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\""; //die ("Please try again, ensuring that you fill out all the fields!"); else { //echo "Your data has been saved"; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')"; $insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); $id = mysql_insert_id(); echo "Thank you, Your logbook entry has been saved."; } } ?> <p>Use this form to add an entry to your logbook.</p> <form name = "form1" method ="post" action=""> <table width="650" border="1" cellspacing="0" cellpadding="5"> <tr> <td>Required *</td> <td> </td> <td>This Format Only</td> </tr> <tr> <td width="180">Date *</td> <td width="300"> <input type="text" name="date" id="date" size = "25"/> </label> <input type="submit" name="today" id="today" value="Add Today" /></td> <td width="170">YYYY-MM-DD</td> </tr> <tr> <td>Aircraft Type *</td> <td><input type="text" name="type" id="type" size = "40" /></td> <td>E.G. Quantum</td> </tr> <tr> <td>Reg Number *</td> <td><input type="text" name="reg_01" id="reg_01" size = "5" /> - <input type="text" name="reg_02" id="reg_02" size = "15"/></td> <td>G - ABCD</td> </tr> <tr> <td>Captain *</td> <td><input type="text" name="captain" id="captain" size = "40" /></td> <td>Name of Captain</td> </tr> <tr> <td>Passenger or Student</td> <td><input type="text" name="passenger" id="passenger" size = "40" /></td> <td>Were you? P or S</td> </tr> <tr> <td>Flight From *</td> <td><input type="text" name="where_01" id="where_01" size = "40" /></td> <td>Take off Airfield</td> </tr> <tr> <td>Flight To *</td> <td><input type="text" name="where_02" id="where_02" size = "40" /></td> <td>Landing Airfield</td> </tr> <tr> <td>Takeoff GMT *</td> <td><label>Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size = "10" /> Min <input type="text" name="takeoff_min" id="takeoff_min" size="10"/> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Landing GMT *</td> <td><label>Hr <input type="text" name="landing_hr" id="landing_hr" size="10" /> Min <input type="text" name="landing_min" id="landing_min" size="10" /> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Captain Weighshift</td> <td><label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_captain_min" id="ws_captain_min" size = "10" /> <input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" /> <!--This is the button I would like to take the time from the take off and put it into the captain weightshift hrs and min boxes --> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student Weightshift</td> <td><label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" /> <input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Captain 3 Axis</td> <td><label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_captain_min" id="three_captain_min" size = "10" /> <input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student 3 Axis</td> <td><label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_student_min" id="three_student_min" size = "10" /> <input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Passenger Interest Only</td> <td>Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10"/> Min <input type="text" name="passenger_min" id="passenger_min" size="10"/> <input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" /></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Remarks</td> <td><textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td> <td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td> </tr> <tr> <td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td> <td><input type="submit" name="reset" id="reset" value="Reset Form" /></td> <td> </td> </tr> </table> <p> </p> <p> </p> </body> </html> Hi there, I think this is a big question but I'd appretiate any help you can provide!! I have a list of items and subitems in a table that looks like this: id parent_id title 1 0 House Chores 2 1 Take Out Trash 3 1 Clean Room 4 0 Grocery List 5 4 Eggs 6 4 Produce 7 6 Lettuce 8 6 Tomato 9 4 Milk I want to display it like this: (+) House Chores: > Take Out Trash > Clean Room (+) Grocery List: > Eggs (+) Produce > Letutce > Tomato > Milk So basically each entry in the table has an unique id and also a parent id if it's nested inside another item. I "sort of" got it figured out in one way, but it doesnt really allow for nested subgroups. I'd like to know how would y'all PHP freaks to this Also taking suggestions for the javascript code to expand/collapse the tree !! Thank you! |