Jump to content

punk_runner

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

punk_runner's Achievements

Member

Member (2/5)

0

Reputation

  1. Yeah sorry... This works I believe: $_query = "SELECT products.sku, products.photo FROM products LEFT JOIN stores ON products.store_id = stores.id WHERE stores.status = 1 AND stores.visibility = 1 ORDER BY RAND() LIMIT 8";
  2. Ver 14.12 Distrib 5.0.45 I have a table with stores and a table with products, with a foreign key on store_id. Products belong to a store. I need to pull 8 random products but only if the store they belong to has a status of 1 and visibility of 1 (some stores are hidden/private, we don't want to display those products)... I don't want to add status and visibility columns to the products table, that's not normalized. Here's my query, it is pulling from all stores, even if status or visibility is 0, why? $_query = "SELECT products.sku, products.photo, stores.store_id FROM products, stores WHERE stores.status = 1 AND stores.visibility = 1 ORDER BY RAND() LIMIT 8";
  3. Try: $newArr = array_reverse($arr); echo $newArr; or asort($arr);
  4. Always check that the value submitted is what it is supposed to be. For example, if you are expecting a zip code, only allow numbers and letters, a dash and a space (for Canadian)... disallow all other characters. It's probably a good idea NOT to call your database columns "username" and "password" - call them something like "x_username" or "user_password" so it is hard to guess. Force 8+ character passwords... When you want to get really secure use prepared statements.
  5. Here is how I validate and insert an email, it's in a class method. I use PDO and so should you. Here a link about it: http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ private validateEmail($email) { // access the PDO:: Database Connection Class require_once("../database.class.php"); // force email address to all lowercase for easier reading // variable is private so it starts with underscore $_email = strtolower($email); // make sure the email address is not empty // this may seem redundant since the following regex will // catch it however the regex is slow, this is fast, thus first. if (empty($_email)) { $_SESSION['error'] = "Please provide a valid email address, foo!"; $_status = 'FALSE'; } // make sure email address is valid use email validation regex elseif (!preg_match('/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i', $_email)) { $_SESSION['error'] = "That is not a valid email address, foo!"; $_status = 'FALSE'; } // make sure the email address is not already in use else { // SQL query string to retrieve the user ID if the email address is in use $_sql = "SELECT id FROM users WHERE email = :email LIMIT 1"; try { // Build the query transaction $db->beginTransaction(); // Build the prepared statement $_stmt = $db->prepare($_sql); // Bind the parameters to their properties $_stmt->bindParam(":email", $_email, PDO::PARAM_STR); // Execute the query $_stmt->execute(); // Commit to the transaction $db->commit(); // Fetch the results $_dBSelectResults = $_stmt->fetchAll(PDO::FETCH_ASSOC); if ((count($_dBSelectNumRows) != 0)) { $_SESSION['error'] = "That email address is already in use, foo!"; $_status = 'FALSE'; } else { $_cleanEmail = $_email; } } catch(PDOException $e) { // Roll back the transaction if we fail $dbh->rollback(); $_SESSION['terror'] = 'Error: ' . $e->getMessage(); $_status = 'FALSE'; } } // Insert the new email address (and other fields) into the database try { $db->beginTransaction(); $_insertUser = $db->prepare("INSERT INTO `users` (email,password) VALUES (:email,:password)"); $_insertUser->bindParam(':email', $_cleanEmail, PDO::PARAM_STR); $_insertUser->bindParam(':password', $_cleanPassword, PDO::PARAM_STR); $_insertUser->execute(); $db->commit(); } catch(PDOException $e) { $db->rollBack(); $_SESSION['terror'] = 'Error: ' . $e->getMessage(); $_status = 'FALSE'; }
  6. I have been trying to get the new FedEx Web Services working for a week and I just cannot make any progress. I am using PHP of course, my server is CentOS Linux with SOAP compiled in, running PHP 5. I have a FedEx developer account with all of the credentials and I have downloaded the WSDL file and sample code and I *think* put all of my credentials in the right place but I just keep getting errors. The most recent error is this: ------------------------------------------------------ Fault Code:soapenv:Server String:Schema validation failed for request. ------------------------------------------------------ Can someone maybe start from scratch and help me out here? I am not running any framework or eCommerce systems, just pure object oriented PHP5. I am fluent in PHP but I know very little about web services and am up against a deadline :-( I simply need to use our FedEx account to submit a delivery address etc. to buy the postage (create a shipment), save the shipping label as a PDF and get a tracking number. I will worry about address validation once I get the rest working. Can anyone tell me exactly what files I would need and what variables need changed in these files, so can I make sure I am not forgetting anything? or does anyone have a nice FedEx Web Services class handy to make things easy?
  7. I have a PHP app that I wrote that requires a new IP address each time that it is run. Currently I use Tor on my desktop and the Vidalia app to change the Tor identity each time I run the script but I want to automate this. Can anyone help with switching Tor identities with PHP? Essentially after my script runs I need to call a function that switches to a new Tor identity. I have the following code but it doesn't seem to work, and I am not sure why. I am running this from XAMPP on OSX, Tor is running locally (client not server)... in my Tor settings I have 127.0.0.1 and port 9051, set to "no password"... <?php function tor_new_identity($tor_ip='127.0.0.1', $control_port='9051', $auth_code='') { $fp = fsockopen($tor_ip, $control_port, $errno, $errstr, 30); if (!$fp) { return false; //can't connect to the control port } fputs($fp, "AUTHENTICATE $auth_code\r\n"); $response = fread($fp, 1024); list($code, $text) = explode(' ', $response, 2); if ($code != '250') { return false; //authentication failed } //send the request to for new identity fputs($fp, "signal NEWNYM\r\n"); $response = fread($fp, 1024); list($code, $text) = explode(' ', $response, 2); if ($code != '250') { return false; //signal failed } fclose($fp); return true; } tor_new_identity(); ?>
  8. Store the amount of time left as an integer in the database, as a UNIX timestamp so it is in seconds. Each time 10 seconds is added just add it to that number... $newTime = $oldTime + 10; You can use Axax to update the page every 5 seconds or so...
  9. Yes but it isn't correct OOP to pass $_GET or $_POST to a class, you pass it through a setter method etc...
  10. So I have a simple login modal box (jQuery) that pops up when you click a "login" link... I also have a nice PHP class to handle authentication. I need to pass the username and password values to the class with AJAX and return TRUE or FALSE, or whatever, and then redirect to the user account or display an error. How do I pass these values into a class and get the results back with AJAX? I know how to do it with $_GET but I need to pass them as arguments like this: $login = new Login($username, $password); $result = $login->getResult(); How does that fit in with AJAX so I don't have to reload the page if there's an error?
  11. I currently redirect all non-file, non-directory HTTP requests to the front controller of my MVC framework with this bit of mod-rewrite: <IfModule mod_rewrite.c> RewriteEngine on # if there's only one URL bit, load it as a file # this is for things like login.php, contact.php etc. RewriteRule ^([^/]+)/$ $1.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # route all remaining URL's to the front controller RewriteRule .* index.php [L] </IfModule> However, I need to add a trailing slash to my URLs. Since the typical way to add a trailing slash is to use a 301 redirect to the URI with the slash concatenated, it conflicts with my redirect to the front controller (you can only redirect once)... Any ideas on how I can add the slash before it is redirected, so that the URI carries forward to the front controller with the trailing slash in tact? Not having the trailing slash is screwing with my breadcrumb class further down the code road...
  12. I currently redirect all non-file, non-directory HTTP requests to the front controller of my MVC framework with this bit of mod-rewrite: <IfModule mod_rewrite.c> RewriteEngine on # if there's only one URL bit, load it as a file # this is for things like login.php, contact.php etc. RewriteRule ^([^/]+)/$ $1.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # route all remaining URL's to the front controller RewriteRule .* index.php [L] </IfModule> However, I need to add a trailing slash to my URLs. Since the typical way to add a trailing slash is to use a 301 redirect to the URI with the slash concatenated, it conflicts with my redirect to the front controller (you can only redirect once)... Any ideas on how I can add the slash before it is redirected, so that the URI carries forward to the front controller with the trailing slash in tact? Not having the trailing slash is screwing with my breadcrumb class further down the code road...
  13. The idea is to repeat as little information as possible in the database, right? What I am worried about is that if I have a product that comes in three colors and three sizes, I have nine varieties, and if I have one row for each of them in the products_table, each of those rows has the same description, title, price etc... that seems repetitive. This is a large site, they did $550,000 in sales last year and expect $2M this year, so my redesign has to really be robust.
×
×
  • 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.