Jump to content

m_tyhurst2002

Members
  • Posts

    31
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

m_tyhurst2002's Achievements

Member

Member (2/5)

0

Reputation

  1. You'll probably want to start with a local development server like WAMP or EasyPHP Devserver. http://www.wampserver.com/en/ http://www.easyphp.org/easyphp-devserver.php You will need to turn on error_reporting, display_errors, log_errors, ect. in the php.ini file for debugging. Good luck!
  2. I have an array of data where a user can delete names and their value, like below. This is what the array looks like after a couple are deleted: [0] => Array ( [name1] => [value1] => [name2] => Name [value2] => 10 [name3] => Another name [value3] => 20 [name4] => [value4] => [name5] => And Another [value5] => 40 ) I need to dynamically move up the values if any are deleted, so the array becomes: [0] => Array ( [name1] => Name [value1] => 10 [name2] => Another name [value2] => 20 [name3] => And Another [value3] => 40 [name4] => [value4] => [name5] => [value5] => ) I need to keep all named keys in the array too. Has anyone ran across this problem?
  3. Hello, first off, I don't have a lot of programming experience. I am working off a YouTube tutorial... I am working with a simple PHP/MYSQL shopping cart that only supports one category and a Paypal checkout/add to cart button. My index.php page successfully shows the items that are in the database with the products() function. I have another function that shows the carts contents, cart(). That successfully displays the carts contents, if available. What I am trying to do is create another function cart_qty() to break apart the contents of cart() to see how many items there are. I would like to display, "You have 1 item" or "...2 items", ect. Any thoughts or helpful direction would be awesome! index.php <?php require 'cart.php'; ?> <!DOCTYPE html> <head> </head> <body> <div class="container"><!-- start container --> <div class="sixteen columns"> <h1 class="remove-bottom" style="margin-top: 40px">Test Shpping Cart </h1> <hr /> </div> <div id="products" class="two-thirds column"> <h1>Products In Our Store</h1> <?php echo products(); ?> </div> <div id="shoppingcart" class="one-third column"> <h3>Your Cart</h3> <?php echo cart(); ?> <br> <br> <br> <?php echo cart_qty(); ?> </div> </div><!-- end container --> </body> </html> cart.php <?php // Start the session session_start(); //session_destroy(); //error_reporting(0); $page = 'index.php'; mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('cart') or die(mysql_error()); // add item to cart if (isset($_GET['add'])) { $quantity = mysql_query('SELECT id, quantity FROM tblProducts WHERE id=' . mysql_real_escape_string((int)$_GET['add'])); //prevents SQL injections 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 one item from cart if (isset($_GET['remove'])) { $_SESSION['cart_' . (int)$_GET['remove']] --; header('Location: ' . $page); } // delete item item from cart if (isset($_GET['delete'])) { $_SESSION['cart_' . (int)$_GET['delete']] = '0'; header('Location: ' . $page); } // display list of products function products() { $get = mysql_query('SELECT id, name, description, price, shipping FROM tblProducts WHERE quantity > 0 ORDER BY id ASC'); if (mysql_num_rows($get) ==0) { echo 'There are no products to display!'; } else { while($get_row = mysql_fetch_assoc($get)) { echo '<p>' . $get_row['name'] . '<br>' . $get_row['description'] . '<br>' . number_format($get_row['price'], 2) . '<br>' . $get_row['shipping'] . '<br><a href="cart.php?add=' . $get_row['id'] . '">Add</a></p>'; } } } //generate inputs required by PayPal 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, price, shipping FROM tblProducts WHERE id=' . mysql_real_escape_string((int)$id)); //prevents SQL injections while($get_row = mysql_fetch_assoc($get)) { $num++; echo '<input type="hidden" name="item_number_' . $num . '" value="' . $id . '">'; echo '<input type="hidden" name="item_name_' . $num . '" value="' . $get_row['name'] . '">'; 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 . '">'; } } } } } //display how many items are in the cart function cart() { foreach($_SESSION as $name => $value) { if($value>0) { if(substr($name, 0, 5) == 'cart_') { //get exact number after "'cart_'$id" $id = substr($name, 5, (strlen($name)-5)); //echo $id; $get = mysql_query('SELECT id, name, price FROM tblProducts WHERE id=' . mysql_real_escape_string((int)$id)); //prevents SQL injections 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) . '<a href="cart.php?remove=' . $id .'">-</a> <a href="cart.php?add=' . $id .'">+</a> <a href="cart.php?delete=' . $id .'">delete</a><br>'; } } $total += number_format($sub, 2); } } if ($total == 0) { echo "Your cart is empty."; } else { echo 'Total: $' . number_format($total, 2) . ''; ?> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="someone@yahoo.com"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> <?php } } function cart_qty() { ///how many items are in cart } ?>
  4. I have one page actually, the first option that appears on that page is a SELECT dropdown where they select how many people, and submit. When they submit, it reloads the same page with other options (the first option goes away after submitting). The new options, when clicked on, goes to a PayPal cart. From that cart, when they click "continue shopping" it reloads my page and the user has to select how many people again. I would just like it if the SELECT OPTION remembered how many people they chose the first time. Hope that makes sense.
  5. Hi guys, newb here, trying to get sessions to work form me. I am having difficulty incorporating SESSIONS into my dynamic SELECT OPTION. At the very top of my page I am starting SESSION code and POSTing "people" from the form. <?php session_start(); // start session $totalpeople = $_POST['people']; //post number of tanks from form ?> This is my SELECT OPTION code. <select name="people"> <? for ($i=1;$i<100;$i++) { $selected = ""; if ($i==$totalpeople) $selected = (isset($_SESSION['people']) && $i == $_SESSION['people']) ? ' selected' : ''; print ("<option value='" . $i . "' " . $selected . ">" . $i . "</option>\n"); } ?> </select> Any help or insight would be greatly appreciated!
  6. The empty array was wrong. Instead of this, $thumbImg[] = array(); It's supposed to be, $thumbImg = array(); Thanks for your help Adam!!
  7. It outputs, "array(0) { } string(192) " " string(192) " " string(192) "", along with the images. Thanks for the quick reply!!
  8. Awesome, thank you very much!! It works beautifully with the $exceptions array. I do have one more question. Where I am printing the FOR loop, it outputs the word "array" right before the images. Is the loop incorrect somehow? Thank you so much for your help! <? for ($i=0; $i<count($thumbImg); $i++) print $thumbImg[$i]; ?>
  9. Hello guys and gals, I am pretty green to PHP! I have an empty array that that I am trying to put images into. The thing is I have a certain file name in the folder, I want to exclude that file. This is what I have tried, any advice would be appreciated! $thumbImg[] = array(); foreach (glob($DImg) as $PImg) { if (!is_file("thumbnail.jpg")) { $thumbImg[] = "<img src=\"pathtoimage\">"; } } Later on the page I am printing it out with this. It is still including the thumbnail.jpg image. Thank you in advance!! for ($i=0; $i<count($thumbImg); $i++) print $thumbImg[$i];
  10. Thanks, glob() was able to do it all kind of. Changed file names for the ones that I want shown to have "www_" at the begining. <?php $dir = "img/portfolio/www_*"; foreach (glob($dir) as $file) { echo '<img src="' . $file . '" longdesc="' . $file . '" width="800" height="481" />'; } ?> I am trying to learn... I guess I wouldn't need to closedir() if I didn't opendir() right, since I am using glob()? Thanks
  11. Hey guys, I have a folder which has images. In this folder there are images that start with "refl_". I want to make sure those are not displayed. This is what I tried and it does not work. I want to show all images that don't start with "refl_". I am new to this as I am sure some can see. Thanks for the help if possible! <?php $dir = opendir("img/portfolio/"); while (false !== ($file = readdir($dir))) { $pos = strpos($file, "refl_"); if ($pos == false) { echo '<img src="img/portfolio/' . $file . '" longdesc="img/portfolio/' . $file . '" /></a>'; } } ?>
  12. I did everything as suggested. This is the php file I am using... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/ DTD/xhtml1-transitional.dtd"> <?php $Checked = false; if (isset($_POST['submit'])) { $pickupdate = $_POST['pickupdate']; $pickuptime = $_POST['pickuptime']; $AMPM = $_POST['AMPM']; $lastname = $_POST['lastname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $cellphone = $_POST['cellphone']; $pickuplocation = $_POST['pickuplocation']; $destination = $_POST['destination']; $airline = $_POST['airline']; $flightnumber = $_POST['flightnumber']; $orderedbyname = $_POST['orderedbyname']; $orderedbynumber = $_POST['orderedbynumber']; $company = $_POST['company']; if ( !empty($pickupdate) && !empty($pickuptime) && !empty($AMPM) && !empty($lastname) && !empty($firstname) && !empty($email) && !empty($cellphone) && !empty($pickuplocation) && !empty($destination) && !empty($airline) && !empty($flightnumber) && !empty($orderedbyname) && !empty($orderedbynumber) && !empty($company)) { if(isset($_POST['submit'])) { $to = "m_tyhurst2002@yahoo.com"; $subject = "sdf"; $strEmail = "email.html"; $objFile = fopen($strEmail, 'rb'); $strData = fread($objFile, filesize($strEmail)); fclose($objFile); $strHeaders = "From: $email_field"; $strHeaders .= "MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1"; $arrBody["LNAME"] = $_POST['lastname']; $arrBody["FNAME"] = $_POST['firstname']; $arrBody["EMAIL"] = $_POST['email']; $arrBody["PUDATE"] = $_POST['pickupdate']; $arrBody["PUTIME"] = $_POST['pickuptime']; $arrBody["AMPM"] = $_POST['AMPM']; $arrBody["CELL"] = $_POST['cellphone']; $arrBody["PULOCATION"] = $_POST['pickuplocation']; $arrBody["DESTINATION"] = $_POST['destination']; $arrBody["AIRLINE"] = $_POST['airline']; $arrBody["FLIGHTNO"] = $_POST['flightnumber']; $arrBody["ORDEREDBY"] = $_POST['orderedbyname']; $arrBody["ORDEREDBYNO"] = $_POST['orderedbynumber']; $arrBody["COMPANY"] = $_POST['company']; $arrBody["COMMENTS"] = $_POST['comments']; foreach($arrBody as $strKey => $strVal) { $strBody = str_replace("[".strtoupper($strKey)."]", $strVal, $strBody); } $Checked = true;//Checked mail($to, $subject, $strBody, $strHeaders); } else { echo "blarg!"; } } else { $error = true; } } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/main.css"/> </head> <body> <?php if($Checked) { echo "<script type='text/javascript'>location.href='http://yahoo.com'</script>"; } ?> <p> <h2> Please fill out the online reservation form below so we can serve you more efficiently. All fields are required to submit the form. Please note that we require at least 24 hours notice for any cancellation. If you are in need of service within the next 24 hours please bypass this step and contact us directly.</h2> <p> </p> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table width="775" height="422" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="275" height="22" scope="row"><p align="left">Pickup Date: (mm/dd/yyyy) </p></th> <td width="500"><input name="pickupdate" type="text" value="<?php echo $pickupdate; ?>" size="10" maxlength="10"><span class="resistratioerror"><?php if ( $error==true && empty($pickupdate) ) { echo 'Please enter pickupdate.<br>'; } ?></span></td> </tr> <tr> <th height="24" scope="row"><p align="left">Time:</p></th> <td><input name="pickuptime" type="text" size="10" maxlength="10"> <select name="AMPM"> <option value="0" <?php if (empty($AMPM)) echo "selected"; ?>>- Select -</option> <option value="AM">AM</option> <option value="PM">PM</option> </select> <span class="resistratioerror"><?php if ( $error==true && empty($pickuptime) ) { echo 'Please enter pick-up time.'; } ?><?php if ( $error==true && empty($AMPM) ) { echo 'Select AM/PM.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Last Name:</div></th> <td><input name="lastname" type="text" value="<?php echo $lastname; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($lastname) ) { echo 'Please enter Last Name.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">First Name:</div></th> <td><input name="firstname" type="text" value="<?php echo $firstname; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($firstname) ) { echo 'Please enter First Name.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"><div align="left">Email:</div></th> <td><input name="email" type="text" value="<?php echo $email; ?>" /><span class="resistratioerror"><?php if ( $error==true && empty($email) ) { echo 'Please enter Email address.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Cell Phone:</div></th> <td><input name="cellphone" type="text" value="<?php echo $cellphone; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($cellphone) ) { echo 'Please enter Cell Phone.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Pickup Location:</div></th> <td><input name="pickuplocation" type="text" value="<?php echo $pickuplocation; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($pickuplocation) ) { echo 'Please enter Pick-Up Location.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Destination:</div></th> <td><input name="destination" type="text" value="<?php echo $destination; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($destination) ) { echo 'Please enter Destination.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Airline:</div></th> <td><input name="airline" type="text" value="<?php echo $airline; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($airline) ) { echo 'Please enter Airline.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Flight Number:</div></th> <td><input name="flightnumber" type="text" value="<?php echo $flightnumber; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($flightnumber) ) { echo 'Please enter Flight Number.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Ordered by Name:</div></th> <td><input name="orderedbyname" type="text" value="<?php echo $orderedbyname; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($orderedbyname) ) { echo 'Please enter Ordered By Name.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"><div align="left">Ordered by Number:</div></th> <td><input name="orderedbynumber" type="text" value="<?php echo $orderedbynumber; ?>" /><span class="resistratioerror"><?php if ( $error==true && empty($orderedbynumber) ) { echo 'Please enter Ordered by Number.<br>'; } ?></span></td> </tr> <tr> <th height="22" scope="row"> <div align="left">Company:</div></th> <td><input name="company" type="text" value="<?php echo $company; ?>"><span class="resistratioerror"><?php if ( $error==true && empty($company) ) { echo 'Please enter Company.<br>'; } ?></span></td> </tr> <tr> <th height="24" valign="top" scope="row"> <div align="left">Comments:</div></th> <td><textarea name="comments" cols="35" rows="4" id="comments"></textarea></td> </tr> <tr> <th height="24" scope="row"><div align="left"></div></th> <td><input type="reset" value="Reset"> <input type="submit" name="submit" value="Submit"></td> </tr> <tr> <th height="24" scope="row"> <div align="left" class="receiptlink"> <p><a href="ETReceipt.pdf">Downloadable Receipt</a></p> </div></th> <td><p> </p> </td> </tr> </table> </form> </body> </html> This is the html file I am using. <!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> <body> Last Name: [LNAME]<br /> First Name: [FNAME]<br /> Email: [email]<br /> Pick-Up Date: [PUDATE]<br /> Pick-Up Time: [PUTIME]<br /> AM/PM: [AMPM]<br /> Cell Phone: [CELL]<br /> Pick-Up Location: [PULOCATION]<br /> Destination: [DESTINATION]<br /> Airline: [AIRLINE]<br /> Flight Number: [FLIGHTNO]<br /> Ordered By Name: [ORDEREDBY]<br /> Ordered By Number: [ORDEREDBYNO]<br /> Company: [COMPANY]<br /> Comments: [COMMENTS]<br /> </body> </html> I cannot understand what the deal is... Thank you sooo much for your continued help!
  13. I crossed my fingers... No such luck this time though. The permissions on the html file is 755 is this correct? Thanks
  14. Wow! Thank you so much for your help. When I fill out the fields of the for and click submit I get an email but the email is empty... Is this the right code now? <?php $Checked = false; if (isset($_POST['submit'])) { $pickupdate = $_POST['pickupdate']; $pickuptime = $_POST['pickuptime']; $AMPM = $_POST['AMPM']; $lastname = $_POST['lastname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $cellphone = $_POST['cellphone']; $pickuplocation = $_POST['pickuplocation']; $destination = $_POST['destination']; $airline = $_POST['airline']; $flightnumber = $_POST['flightnumber']; $orderedbyname = $_POST['orderedbyname']; $orderedbynumber = $_POST['orderedbynumber']; $company = $_POST['company']; if ( !empty($pickupdate) && !empty($pickuptime) && !empty($AMPM) && !empty($lastname) && !empty($firstname) && !empty($email) && !empty($cellphone) && !empty($pickuplocation) && !empty($destination) && !empty($airline) && !empty($flightnumber) && !empty($orderedbyname) && !empty($orderedbynumber) && !empty($company)) { if(isset($_POST['submit'])) { $to = "whatever@yahoo.com"; $subject = "XXX"; $strEmail = "email.html"; $objFile = fopen($strEmail, 'rb'); $strData = fread($objFile, filesize($strEmail)); fclose($objFile); $strHeaders = "From: \r\n"; $strHeaders.= "MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1"; $arrBody["LNAME"] = $_POST['lastname']; $arrBody["FNAME"] = $_POST['firstname']; $arrBody["EMAIL"] = $_POST['email']; $arrBody["PUDATE"] = $_POST['pickupdate']; $arrBody["PUTIME"] = $_POST['pickuptime']; $arrBody["AMPM"] = $_POST['AMPM']; $arrBody["CELL"] = $_POST['cellphone']; $arrBody["PULOCATION"] = $_POST['pickuplocation']; $arrBody["DESTINATION"] = $_POST['destination']; $arrBody["AIRLINE"] = $_POST['airline']; $arrBody["FLIGHTNO"] = $_POST['flightnumber']; $arrBody["ORDEREDBY"] = $_POST['orderedbyname']; $arrBody["ORDEREDBYNO"] = $_POST['orderedbynumber']; $arrBody["COMPANY"] = $_POST['company']; $arrBody["COMMENTS"] = $_POST['comments']; foreach($arrBody as $strKey => $strVal) { $strBody = str_replace("[".strtoupper($strKey)."]", $strVal, $strBody); } $Checked = true;//Checked mail($to, $subject, $headers, "From:$email_field"); } else { echo "blarg!"; } } else { $error = true; } } ?> Thank you very much for helping me with this!!! I just used the email template that you posted. The email.html file is in the root of where the form.php file is that has the code. Is this all correct? Thanks
  15. I really don't know much about PHP. I guess what I don't understand with what you replied is how I would get the variables like $pickuptime or $pickupdate, etc. How does the html email grab those variables? Do I use the script you wrote and put it in the existing one I have or is this separate. This is kind of hard to explain I guess, maybe confusing myself as well!... Does this make any sense? Thanks for your help and patience!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.