Jump to content

Strider64

Members
  • Posts

    473
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by Strider64

  1. While ignace in my opinion is a more elegant and better solution(s), I think the following would prevent duplication if you added this to the adam_bray's class: // Empty clone magic method to prevent duplication: private function __clone() { }
  2. I found a good way to test it is take the url from one browser (while logged in) and try it in another browser. It won't allow you to stay logged in. I know I have tried it, it works like a charm.
  3. If you know the items to be unchecked or checked then why don't you just update them? I'm assuming that each item has an unique id, thus you could just update the selected id rows. Interestingly I have built something similar and all I do is : $id = $_POST['id']; if ( isset($_POST['checked'])) { $checked = $_POST['checked']; $query = 'UPDATE thelist SET checked=:checked, dateAdded=NOW() WHERE id=:id'; $stmt = $pdo->prepare($query); $result = $stmt->execute(array(':checked' => $checked, ':id' => $id)); } I do this real time using AJAX, but this could be modified to something that you are doing. I am guessing that it will entail using array and a loop. To see a working example of what I'm talking about : http://www.thegrocerylist.us/ I would also break down what you do in sections (methods/functions), for example add function, update function(s) and delete functions. You'll be surprise that you will have about the same amount of code ( maybe even less).
  4. I wrote a trivia game in Flash and the used a MySQL database, but I have since converted the trivia game over to JQuery, PHP and AJAX. The one thing that has remain constant over all these years is the query string (with minor changes obviously): $query = 'SELECT id, question, answerA, answerB, answerC, answerD, correct FROM movieTrivia WHERE id>=:current_id ORDER BY id ASC LIMIT 1'; Your code looks like it doesn't have individual answers, I could be wrong for I just did a quick look over of your code: If you want you can have a look at the code that I wrote for the trivia game at: http://www.jrpepp.com/displayPage.php?page=189 and a working script at : http://www.pepster.com/
  5. Well, when you asking for help, it is better being nice than it is being rude. "You can catch more flies with honey than vinegar".
  6. I use GeSHi and like it a lot, I feel it's pretty secure. You don't have to store anything in the database thus nothing to worry about security when it comes to that portion of the code. I tried writing my own highlight script and found it was a pain in the butt, plus I don't have worry about security for that portion like I said.
  7. I don't know how you have it set up, but I check my database to see how many images are in the directory, then just add 1 for the new image. I pretty sure you could count on how many image files are in the directory also. For example I do the following: $query = "SELECT * FROM pictures WHERE subDirectory=:subDirectory"; $stmt = $pdo->prepare($query); $stmt->execute(array(':subDirectory' => $name)); $result = $stmt->fetchAll(); $fileNumber = count($result) + 1; $result = null; if ($fileNumber < 10) { $this->uniqueFileName = $name . '-0' . $fileNumber; } else { $this->uniqueFileName = $name . '-' . $fileNumber; } Before anyone says I anything I know I could had done the count in the $query. This way it insures that I have a unique name and there is even a way to prevent duplicates doing it through PDO, but for my purposes I don't think a duplicate will happen and if I does I'll add the added code.
  8. var params = { vehicle_plate: vp, vehicle_model: vm, vehicle_type: vt, date_acquired: da, assigned_driver: ad }; // Set parameters var dataString = jQuery.param( params ); // Set parameters to correct AJAX format $.ajax({ type:"post", url:"process.php", data: dataString, success:function(info){ $('#result').html(info); // Display the result back when saved: } });
  9. Let me get put my psychic hat on.
  10. I created a countdown timer using PHP, AJAX and JQuery, I'm sure you could modify it to your needs if you want. It's up to you. countDownTimer.zip
  11. $con=mysqli_connect("localhost","root","your_password","demo"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql ="CREATE TABLE IF NOT EXISTS `people` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(15) NOT NULL, `gender` char(15) NOT NULL, `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5" ; if (mysqli_query($con,$sql)) { echo "Database my_db created successfully"; } else { echo "Error creating database: " . mysqli_error($con); } Even threw in a timestamp.
  12. Just a little side note, if you want to have the time look like a 24-hour clock the format would be: $tomorrow_date = date('Y-m-d g:i:s A', strtotime($date_and_time . ' + 1 day')); This just saves you from looking the formatting up.
  13. I just wanted to add, you already have the $('.add_to) in your script, just add the inner part of the code to the script.
  14. I'm only guessing but it might simple be fixed by doing this Change this <a href="#" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a> to: <a href="" id="<?php echo $productRow['id'];?>" class="add_to">ADD TO CART</a> I think the href="#" is causing the page to go to the top or you can disable it in script (which probably is the better of the two options and probably won't cause any problems) : I'm assuming you're using jQuery: $(".add_to").on('click', function(e){ e.preventDefault(); $(this).removeAttr( "href" ); });
  15. Just a suggestion, but this seems to me to be more suited for JavaScript (maybe even use a library such as jQuery?) than PHP.
  16. Something tells me that djclewes will be back with further problems. Just a hunch....
  17. .content-wrap { box-sizing: border-box; /* more code here... */ } Maybe doing something like this? Though looking at the problem again probably not.
  18. Another approach would be to use Modernizr : http://modernizr.com/ which lends itself to support older browser versions. I also found out when dabbling with JavaScript to use a library (I know I'm going to get slammed by JavaScript purists) such as JQuery, that way what looks good in Firefox looks good in Chrome, etc...(Well, 99 percent of the time). Another thing I have learned over the last couple of years is even though I might be writing in HTML5, I still write as if I'm using a stricter mode of HTML (one of my first college instructors even taught that way). This lends to writing cleaner code in the long run and staying away from bad habits that HTML5 tends to lend itself to in my opinion.
  19. if you want to pull a value out of the drop down using PHP then you need this: <select name="automaker"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select> This would give the web page graceful degradation in my opinion with people disabling JavaScript.
  20. It's a little tricky using just straight PHP, but it can be done function displayDir($pdo, $name) { try { // Fetch the images: $query = 'Select id, thumbnail, picName, subDirectory, user_name FROM pictures WHERE subDirectory=:subDirectory ORDER BY id ASC'; $result = $pdo->prepare($query); $result->execute(array(':subDirectory' => $name)); if ($result && $result->rowCount() > 0) { // Check that rows were returned: $result->setFetchMode(PDO::FETCH_CLASS, 'StoredPictures'); // Arm the image class by fetching it: } else { // Problem! throw new Exception('No content is available to be viewed at this time'); } } catch (Exception $e) { // Catch generic exceptions } return $result; } /* Display images & thumbnails when user selects directory */ if (isset($_POST['imageDir']) && $_POST['imageDir'] == 'selected') { $_SESSION['name'] = $_POST['childName']; // Assign category to path: $name = $_SESSION['name']; $resultDir = displayDir($pdo, $name); } <form class="selectDir" id="selectDir" action="imageGallery.php" method="post"> <input type="hidden" name="imageDir" value="selected"> <label class="mySelect" for="mySelection">Choose Directory</label> <select class="mySelection" id="mySelection" name="childName"> <?php echo '<option value="' . $name . '">' . ucfirst($name) . '</option>' ?> <option value="ava">Ava</option> <option value="cammi">Cammi</option> <option value="carter">Carter</option> <option value="grant">Grant</option> <option value="jayreed">JayReed</option> <option value="nolan">Nolan</option> </select> <input class="submitCat" type="submit" name="submitImages" value="Enter"> </form> <div class="container photogallery"> <div class="row bg-header-part3"></div> <ul class="row"> <?php $x = 1; if (isset($resultDir)) { while ($pictures = $resultDir->fetch()) { echo '<li><a class="links" href="' . htmlspecialchars($pictures->getPicName()) . '" ><img data-pic="' . $x . '" class="thumbnails" src="' . htmlspecialchars($pictures->getThumbnail()) . '" alt="Thumbnails"></a></li>'; $x += 1; } } ?> </ul> </div> Though I do use jquery and ajax for the rest, but this gives the web page Graceful Degradation for people who disable JavaScript. Getting back to the script, the main important thing I want to show you is the form itself, I don't propagate the whole form in php (you could though) I just do the part where it's needed. Maybe just looking over the form and maybe glancing over the first script might help you out?
  21. You can always a header.inc.php of some kind and just include at the top of you web pages: For example: <?php require('lib/includes/utilities.inc.php'); include 'lib/includes/header.inc.php'; ?> You can also do something like this (although a little more elaborate in your case) inside the header.inc.php file: if (preg_match("/J.R. Pepp | Website Design/i", $pageTitle)) { $metaDesc = '<meta name="description" content="J.R. Pepp is a Website Design and Development Company based in Livonia, Michigan.">'; } That way all you meta tags (elements) will be on every page and appropriate depending on the page. An for the question what is a meta tag? "Meta elements are the HTML or XHTML <meta … > element used to provide structured metadata about a Web page. Multiple Meta elements with different attributes are often used on the same page. ..."
  22. Personally I would switch from using id to class that way you could do something like this: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> div { display: block; border-bottom: 4px solid #2e2e2e; background-color: orange; padding: 30px; } .container { /* * For IE 6/7 only * Include this rule to trigger hasLayout and contain floats. */ *zoom: 1; width: 100%; max-width: 940px; margin: 0 auto; box-sizing: border-box; -moz-box-sizing: border-box; } .container:after { clear: both; } .container:before, .container:after { content: " "; display: table; } .row { /* * For IE 6/7 only * Include this rule to trigger hasLayout and contain floats. */ *zoom: 1; } .row:after { clear: both; } .row:before, .row:after { content: " "; display: table; } </style> </head> <body> <div class="container">Row 1</div> <div class="container row">Row 2</div> </body> </html>
  23. I think I stick with my proven password hashing library from some egghead at MIT than trust an untested and probably vulnerable password script.
  24. Using position:relative; should do the trick: #scontainer { position: relative; overflow:hidden; height:300px; border-style:solid; border-color:red; }
  25. I highly recommend reading Larry Ullman's :PHP Advanced and Object-Oriented Programming" ---The latest edition, for it help me out a lot. Of course there are many different ways to do a user/members class. Here's how I invoke a Member class: <?php # Member class - Store user info and functions to access/controll the flow of data. class Member { // The member attributes containing required and optional information. // The attributes must correspond to the database table columns: private $id = NULL; private $userType = NULL; // Required (assigned enum) private $username = NULL; // Required private $email = NULL; // Required private $pass = NULL; // Required private $fullName = NULL; private $validation_code = NULL; private $address = NULL; private $city = NULL; private $state = NULL; private $zipCode = NULL; // Method returns the user ID: public function getId() { return $this->id; } // Grab the user's username: public function getUsername() { return $this->username; } // Grab the user's full name: public function getFullName() { return $this->fullName; } // Grab the password: public function getPass() { return $this->pass; } public function getUserType() { return $this->userType; } // Clear the password once user is logged in: public function clearPass() { $this->pass = NULL; } public function getEmail() { return $this->email; } // Method returns a Boolean if the user is an administrator: public function isAdmin() { return ($this->userType == 'admin'); } public function isSysop() { return ($this->userType == 'sysop'); } public function isNewUser() { return ($this->userType == 'public'); } // Method returns a Boolean indicating if the user is an administrator // or if the user is the original author of the provided page: public function canEditPage(Page $page) { return (($this->isAdmin() && ($this->id == $page->getCreatorId())) || $this->isSysop()); } // Method returns a Boolean indicating if the user is an administrator or an author: public function canCreatePage() { return ($this->isAdmin() || $this->isSysop()); } } Then calling it is as simple as this (a part of my login in page): // Check against the database: $query = 'SELECT id, userType, username, email, pass, fullName, address, city, state, zipCode FROM users WHERE username=:username'; $stmt = $pdo->prepare($query); $stmt->execute(array(':username' => $_POST['username'])); $stmt->setFetchMode(PDO::FETCH_CLASS, 'Member'); $stored_user_data = $stmt->fetch(); // Verify Stored Hashed Password against input: if ($stored_user_data) { $result = password_verify($_POST['pass'], $stored_user_data->getPass()); }
×
×
  • 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.