Jump to content

Archadian28

Member
  • Posts

    62
  • Joined

  • Last visited

Everything posted by Archadian28

  1. I have been searching for the past 2 days on how to make this work. If anyone can point me in the right direction it will be greatly appreciated. Thanks.
  2. -> is object oriented programming and => is for arrays $arr = array('bob', 'john', 'frank'); foreach ($arr as $key => $value) { echo $key . ' - ' . $value; } That will output 0 - bob 1 - john 2 - frank read up on OOP (object oriented programming) and arrays Do a google search for them...both are PHP
  3. I believe you are looking for the LIKE method in mysql. http://www.mysqltutorial.org/sql-like-mysql.aspx Ok say you have a first and last name in the database. id first_name last_name 1 John Smith 2 Joe Blow 3 Samantha Beth Now in order to search you can use this: "SELECT first_name, last_name FROM users LIKE 'J%'" and that will return 2 rows. Since there are 2 names that start with J and this could be first or last name. The % tells mysql which way to search, after the letter J% is searching right, before the letter %J searches left and %J% will search both. "SELECT first_name, last_name FROM users LIKE '%th'" will return the names that end in 'th'. Your form would look like this: <form method="post" action="somepage.php"> <input type="text" name="search" size="20" /> <input type="submit" name="submit" value="Search" /> </form> PHP: name="search" would be $_POST['search'] <-- holds the value that was inputted into the text field. name="submit" would be $_POST['submit'] <-- you can do a check to see if the button was clicked. if(isset($_POST['submit']) && isset($_POST['search'])) { // search the database here } else { // either $_POST['search'] or $_POST['submit'] was not set. } Hopefully this clears it up for you .
  4. No, im using the plugin from http://jqueryui.com. The tab plugin. There is code you can use to select tabs using jquery but im not too sure how to implement that 100% lol.
  5. Good question. I guess im used to php URL strings lol. I took it out but still not doing what i want it to do :/.
  6. Can anyone help with this? I mainly want everything after the ? taken out of the URL once the page is visited. I think the link would work then. Its nothing serious but i want everything to work. Thanks.
  7. http://imaginationunleash3d.com/new/ ..you forgot to put /new/ at the end
  8. no its all in the same one
  9. I have a dropdown submenu in the nav bar of my website...when i click on one of them it works fine. When im on the same page as where those links point to they dont seem to work correctly. ex: if i am anywhere else on the website except the portfolio page the links work fine, but when im running the portfolio.php script and i try to click any of the links it just takes me back to the home part of the portfolio page. I will have to post my web address because even im confused about what i just said lol. its imaginationunleash3d .com/new/ jQuery was used to make the slide down divs for the submenu just trying to figure out a way to make all links work whether they are for that particular page or not. Its giving me a headache XD. I forgot to mention that im using jQuery .tab() plugin. When i click the link i want it to open that particular tab, which it does, unless im on the page already.
  10. Hopefully you use $_SESSIONS for the login. You could store their username or somekind of unique ID, probably IP address to a $_COOKIE and check it against the Database on your script and make an online column in the users table and set it to 1 if they are online and 0 if they are not. And do something like this: if (isset($_COOKIE['online'])) { foreach($_COOKIE as $key => $value) { // key being "online" ex. $_COOKIE['online'] with their username stored // db connection $sql = "SELECT username FROM users WHERE username='$value'"; $result = mysql_query($sql); $row = mysql_fetch_object($result) while ($row->online == 1) { // echo $row->username or do a count and echo the number if users online } while ($row->online != 1) { // echo offline users (optional) } } } Im not sure how effective that code is and i would most definitely use mysqli if possible but that should get you headed in the right direction. You would have to run that script everytime one of your pages loads and reloads to check for online users every second. I would suggest putting the code in a function and returning $row->username or the number of users online then use javascript to delete the cookie on window.close and create it again at login. Of course at login when you create the online $_COOKIE update the online column to 1 and in the script above if the username in the cookie does not match the usernames in the table set online to equal 0. There are a few steps im leaving out probably but i think you get the idea . Also setting the time to 0 in setcookie() make it behave like a session. The cookie will delete on the browser close instead of using javascript to check the window.close.
  11. Is TESTIMONIALS supposed to be in the black navigation bar? if so you need to increase the width of it. When its too small it pushes it to the next line. I don't see any letters...must have fixed it.
  12. unless your images folder is in the same folder as your css script you need to change this: background: url(images/button.gif) no-repeat 0 0; To this: background: url(../images/button.gif) no-repeat 0 0; ../ goes back 1 directory. So if you are in the css folder use ../ to go back to the root folder then go into images. Or it could be what Ben said. As far as losing your css file...at least you have this: #button { margin-left: 118px; margin-top: 9px; display: block; float: left; height: 31px; margin-bottom: 0; width: 208px; background: url(images/button.gif) no-repeat 0 0; } #button:hover { background-position: 0 -31px; } lol.
  13. does it tell you which line? and have you tried to google the error code?
  14. Just use the database for that. You will have to use the paypal IPN function to make sure they actually bought the item...you can pass hidden variables to paypal and they will send it back. You should read up on it if you are using paypal to collect money.
  15. In the last bit of code you will notice that I am checking to see if the item exists in the DB as well as the $_SESSION['cart']. Here is the code to check if both exists: This is in my functions script, name it what you want to i believe its functions.php in the video tutorials. function item_exists_db($token) { global $db, $shopcart; if (strlen($token) == 32) { $db->query = "SELECT token FROM products"; $result = $db->sql_query($db->query); while($row = $db->fetch_object($result)) { if ($row->token == htmlentities(addslashes($token))) { return true; } } return false; } else { send_error_loc("TOKEN ERROR", "The token and/or the product doesn't exist."); } } function item_exists($token) { $shopcart = getCart(); foreach ($shopcart->GetItems() as $key) { if ($key == $token) { return true; } } return false; } Also if you want to count the number of items in the shopping cart to show the user here is that code: echo "<div id=\"countItems\">"; $shopcart = getCart(); $count = 0; foreach ($shopcart->GetItems() as $key) { if (!empty($key)) { $count++; } } echo "<p style=\"font-size: 14px; color: black; text-align: center;\">Items In Cart: <b>" . $count . "</b></p>"; echo "</div>"; As i said the $token would be the id from $_SESSION['cart'] and your database. You won't need the strlen($token) == 32 because that checks to make sure the $token is 32 characters long. Maybe you can do some other check there. Good Luck!
  16. It seems like the height of your background is too high. Either reduce the height in pixels or set your background property to fixed. See if that works.
  17. I will paste my code in for this feature. You will have to change a few things because i used the shopping cart videos as a guideline...so my variables arent the same as Ben's. Maybe Ben can help you out by changing them for you since he is such a nice guy This is update and remove functionality. Add this to your ShoppingCart.php class file: public function remove($pid) { foreach ($this->GetItems() as $id) { if ($id == $pid) { unset($this->scart[$pid]); } } } public function updQnty($pid, $qnty) { if ($qnty != 0) { $this->scart[$pid] = intval($qnty); echo $qnty; } else { $this->remove($pid); } } This goes in your shoppingcart_row function in the templates.php file (I think thats what its called.) This is the full function: function shoppingCart_Row(ShoppingCart $shopcart , $pid, $counter) { global $db; $db->query = "SELECT title, body, price, image, token FROM products WHERE token='$pid'"; $result = $db->sql_query($db->query); $row = $db->fetch_object($result); $qnty = $shopcart->getItemQnty($row->token); $price = $row->price; $total = number_format(($qnty * $price), 2); return " <tr bgcolor='#2C2C2C' style='color: #FFFFFF;'> <td align='center' width='20%'> <img width='100' height='100' src='$row->image' alt='No Photo Available' /> </td> <td style='vertical-align: top; font-size: 16px; text-decoration: bold;' align='left' width='45%'> $row->title <input type='hidden' name='item_name_$counter' value='$row->title' /> </td> <td width='10%'><div class='remove'><a href='index.php?page=cart&action=remove&id=$row->token'>Remove</a></div></td> <td> <input id='$row->token' name='qnty' type='text' size='3' onblur='sendVal(this.id)' value='$qnty' /> <input type='hidden' name='quantity_$counter' value='$qnty' /> </td> <td> $$total <input type='hidden' name='amount_$counter' value='$price' /> <input type='hidden' name='item_number_$counter' value='$row->token' /> </td> </tr> "; } Instead of using the id column in the database i use token so you will need to change this. This is the part you will need to add: <td width='10%'><div class='remove'><a href='index.php?page=cart&action=remove&id=$row->token'>Remove</a></div></td> <td> <input id='$row->token' name='qnty' type='text' size='3' onblur='sendVal(this.id)' value='$qnty' /> <input type='hidden' name='quantity_$counter' value='$qnty' /> </td> This is the remove code on my cart script: (forgot to add this in the original post) if(isset($_GET['action']) && $_GET['action'] == "remove") { $pid = $_GET['id']; if (item_exists($pid)) { $shopcart->remove($pid); setCart($shopcart); } else { ?> <script type="text/javascript"> alert('That item does not exist.'); window.location = "javascript: history.go(-1)"; </script> <?php } unset($_GET['action']); unset($_GET['id']); ?> <script type="text/javascript"> alert('The item was removed from the shopping cart.'); window.location = "javascript: history.go(-1)"; </script> <?php } The div class="remove" would just be some CSS for a button to click on and a color change for a mouseover. $row->token identifies each product for me but in your case it would be the $product_id so you will want to replace that. $row->token is just like pulling $row->id from the database but i did it a little differently for inserting ID into the URL...to prevent it. This is the javascript you put on your page to send a request to php on another script to pass values. (Hence the onblur="sendVal(this.id)") function sendVal(id) { var getQnty = document.getElementById(id).value; var token = document.getElementById(id).id; window.location = "index.php?page=cart&qnty=" + getQnty + "&token=" + token; } As you see it is getting the updated quantity value from the form and passing it to Javascript then Javascript is passing it to cart.html: Cart.html $shopcart = getCart(); if (isset($_GET['qnty'])) { $num = htmlentities(addslashes($_GET['qnty'])); $token = htmlentities(addslashes($_GET['token'])); if (item_exists($token) && item_exists_db($token) && is_numeric($num)) { $shopcart->updQnty($token, $num); setCart($shopcart); ?> <script type="text/javascript"> alert('Quantity updated successfully.'); window.location = "javascript: history.go(-1)"; </script> <?php } else { ?> <script type="text/javascript"> alert('That item does not exist.'); window.location = "javascript: history.go(-1)"; </script> <?php } } As i said instead of token it would be the $product_id in your case. The unique value of the item or items since the shoppingcart_row function just outputs 1 row for each product in the shopping cart. If i have missed anything or something doesn't work please post the code and we'll get it sorted out for you. Enjoy! As far as the product coming off when it has sold out you can just store the number of products in the database and everytime someone purchases that particular product just subtract -1 from the database and update the database with that number. You will want to do a check on how many of that item you have between the user clicking on the item to add it to cart and it showing up on the shopping cart list. If that number is 0 then send a message to the user. But you may want to include how many of that product you have somewhere near the product before the user even clicks to add it. Just keeps things simple.
  18. You can google the code for implementing videos into webpages...there are many examples...like this one: http://support.vigilant1.com/KnowledgeBase/tabid/53/aft/4046/Default.aspx Or buy the Dreamweaver MX extension for $15 bucks: http://www.topdreamweaverextensions.com/dreamweaver-video-inserter
  19. Couldn't you use jQuery to do something like that? Get the height of the #main div and have it equal both the #left and #right? Or set them all equal to each other?
  20. Paypal Provides the scripts for you http://www.killersites.com/community/index.php?/topic/4741-instant-payment-notification-problem/page__pid__26373&do=findComment&comment=26373
  21. Paypal provides the scripts for you. Paypal IPN Scripts
  22. Try <?php echo "Hello World."; echo "I am learning this so that these first steps become the future of the STC Web Site."; ?> print() and print_r() is mainly for printing out arrays. the r in print_r() prints the array out in a readable format.
  23. For added security put this at the top of index.php: define('WHATEVER_HERE', true); // Change WHATEVER_HERE to something else... then at the top of every page in templates add this (must be the first thing on the page!..besides session_start(): <?php if (!defined('WHATEVER_HERE')) { header("Location: index.php"); // You can log IPs, redirect to the homepage or send them to a nice error page. } ?> What this does is something is defined on index.php and once you add it to every page in the templates directory they can't just go to http://www.yoursite.com'>http://www.yoursite.com /templates/ index.html...they have to load the index.php file by going to http://www.yoursite.com. Not sure if this can be bypassed or not but i've tested ever route possible but without loading the index.php in the web directory first i was not able to load anything in the templates directory. Also files with just images or anything that normally would not have an index.html or index.php file in that directory you can create a file with just the code i posted above with the IF statement so if they go to http://www.yoursite.com /images/ your whole directory will not be visible it will redirect them to the homepage...you may have to add ../ infront of index.php. This is in response to my other post about security. If you aren't familiar with securing your website google has many tutorials that can help you. Security is #1
  24. Ben is absolutely right. $_SESSION is better because its stored on the server rather than $_COOKIE being stored on the user's computer. I have rewritten the login template with $_SESSION so its more secure. You can go through the files and change usern, user, sess, admin, adchk if you want to but since its $_SESSION and not cookies im not sure you have to . Any problems or questions let me know.
  25. Well i said i would post a template system so here it is: My Directory: classes templates.php images (for the website of course nothing to do with templates ). templates (directory) footer.html header.html index.html whatever.html index.php In the classes folder is the templates class file: templates.php: <?php class Template { var $file; var $incfile; var $assign = array(); protected $tplex = ".html"; protected $tmpdir = 'templates/'; function load($filename) { $file = $this->tmpdir . $filename . $this->tplex; if (file_exists($file)) { $this->template = file_get_contents($file); } else { // Your error message } } function get_contents($contents) { $this->template = file_get_contents($contents); } function inc($incfile) { $file = $this->tmpdir . $incfile . $this->tplex; include $file; } function showPage() { foreach($this->assign as $key => $val) { $this->template = str_replace("{" . $key . "}", $val, $this->template); } eval("?>" . $this->template); } } // end class ?> Now in the templates directory you name your files whatever you want...the MAIN PAGE when they go to your URL HAS to be named index.html or .whatever but make sure you change it from .html to whatever extension you want to use and ALL files in the templates folder MUST have the same extension. Change the extension here: protected $tplex = ".html"; And in the index.php: (below) $chkpg = templates/ . $page . ".html"; this is my index.php file to show the entire website...DO NOT change anything in this or it will not work. // Include the template.php class file in index.php $template = new Template(); // Include header.html $template->inc('header'); // Get the page. If its not set then set it to index. $page = (isset($_GET['page'])) ? htmlentities(addslashes(trim($_GET['page']))) : 'index'; unset($_GET['page']); // Check to make sure the page actually exists on the webserver. If not, take your ass to the homepage...hacker. $chkpg = TEMP_PATH . $page . ".html"; if (!file_exists($chkpg)) { // Error message here if the file in the templates directory does not exist. This keeps this system secure for the most part. don't forget to redirect to the homepage } if(file_exists($chkpg) && isset($page)) { $template->load($page); } else { $template->load('index'); } $template->showPage(); $template->inc('footer'); } now the $template->inc('header') includes this: (VERY important) This is named header.html in my templates folder <!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 name='keywords' content=''> <meta name='description' content=''> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>YOUR TITLE</title> //INSERT any CSS external links to pages or javascript here </head> <body> // Top logo or banner here // Navigation here if your navigation is going across the top. <div> // this is where $template-load($page) displays from index.php and my footer.html: (also very important) <div id="footer"> <p class="content">All images and content belongs to IMAGINATION UNLEASH3D Copyright © 2011-2012. All rights reserved.</p> </div> </div> // Div close after body in header.html </body> </html> So what that does if you look at the index.php any file you create in your templates folder besides the header and footer.html will show up between those two to complete your website. So index.html will be your main page and you might have another file named contactus.html or something like that. ALL your navigation and logo banners go in the header.html the only thing that needs its own page is like the homepage or contact us page or about us page, etc. and that can be done with a simple <div></div>. Now to link to these pages you simply add this to the URL: ?page=contacts ?page=contacts would be contacts.html in your templates folder (not ?page=contacts.html) Here is an example of mine: <div id="nav"> <ul id="buttons"> <li class="home"><a href="index.php"></a></li> <li class="portfolio"><a href="index.php?page=portfolio"></a></li> <li class="reviews"><a href="index.php?page=reviews"></a></li> <li class="aboutus"><a href="index.php?page=aboutus"></a></li> <li class="contact"><a href="index.php?page=contact"></a></li> </ul> </div> <!-- Nav End --> Pay attention to everything in the <a href=""></a> tags. Thats how you link to your pages. If you have any questions just post and i will answer them. Enjoy!. You MUST include the header.html and footer.html with the index.html. All template files go in the templates directory. What this does is run everything through the index.php file so if you have forms ANYWHERE in your website you can simply add action="index.php" to any form and simply get the $_POST or $_GET on the index.php file...i don't recommend this. Make a function file for this and call the function on index.php file. If you have any questions just ask!
×
×
  • Create New...