Jump to content

Azsen

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Azsen's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm building an HTML5/CSS3 site and I've set a style called: .smlFormInput { width: 140px; } So I apply that to the following fields: <input name="firstName" type="text" class="smlFormInput"> <input name="lastName" type="text" class="smlFormInput"> <input name="email" type="email" class="smlFormInput"> <input name="homePhone" type="tel" class="smlFormInput"> Ok now when executed in Firefox all the input boxes line up properly, but on Chrome the type="email" and type="tel" are different lengths (+2px). Kinda making my page look messy with different size text boxes. What's the problem? Chrome specific bug? Many thanks
  2. Has anyone seen a decent database class for nicely wrapping up all the PDO functions? Ideally I'm after an example to handle database errors properly, insert/update/select queries, prepared statements and transactions. I've had a crack at writing my own and it's a bit messy with error handling everywhere. Maybe I need to put that in a separate class or something. E.g. here's how I'd do a database update: $db = new Database(); // In page controller $params['type'] = $type; $params['details'] = $details; $query = 'insert into site_logs (type, details) values (:type, :details)'; $result = $db->preparedUpdate($query, $params); // returns false if error or # of rows if successful Just some examples would be great and I'll re-factor my one to make it better. Thanks!
  3. Perfect! Saved me 60 lines of code just like that. Sometimes find it confusing when to use certain joins for what task so thanks very much!
  4. Hmm tried that with this: SELECT city_name, region_name, country_name FROM locations RIGHT JOIN countries ON locations.country_id = countries.country_id RIGHT JOIN regions ON locations.region_id = regions.region_id RIGHT JOIN cities ON locations.city_id = cities.city_id WHERE locations.location_id = 87 But if I set either the city_id, region_id or country_id to NULL in the locations row it will return nothing in the query. But it should still return the name values where the id is set.
  5. MySQL 5.1.41 PHP 5.3 Ok I've got a table which stores all the data about a user's location (location_id, address, suburb, city_id, region_id, country_id). The city, region and country data are stored in separate tables. Here's my current query: SELECT city_name, region_name, country_name FROM locations INNER JOIN countries ON locations.country_id = countries.country_id INNER JOIN regions ON locations.region_id = regions.region_id INNER JOIN cities ON locations.city_id = cities.city_id WHERE locations.location_id = 87 Which returns: Dunedin | Otago | New Zealand Problem is on some rows of the locations table you will get NULL values in the id columns as the user maybe selected a country, but not a region or city. Now if I run that query again with a location row that has a NULL city_id, region_id or country_id then the query fails and returns no data. I need a simple way to check that if the particular id is NULL and then not get the city/region/country name for that id but get the other non null values. I managed to accomplish this in PHP, but there must be a better way to do it in SQL. I don't think adding IS NOT NULL at the end of the where statement works. $resultB = $db->select("select * from locations where location_id='$locationId'"); foreach ($resultB as $keyB => $valB) { $address = $valB['address']; $suburb = $valB['suburb']; $cityId = $valB['city_id']; $regionId = $valB['region_id']; $countryId = $valB['country_id']; // Get country data if ($countryId !== NULL) { $resultC = $db->select("select country_name from countries where country_id='$countryId'"); foreach ($resultC as $keyC => $valC) { $countryName = $valC['country_name']; } } // Get region data if ($regionId !== NULL) { $resultC = $db->select("select region_name from regions where region_id='$regionId'"); foreach ($resultC as $keyC => $valC) { $regionName = $valC['region_name']; } } // Get city data if ($cityId !== NULL) { $resultC = $db->select("select city_name from cities where city_id='$cityId'"); foreach ($resultC as $keyC => $valC) { $cityName = $valC['city_name']; $cityName = htmlentities($cityName, ENT_NOQUOTES); } } } # foreach This code is actually inside another loop so in effect 3 nested loops. :-\ NB: $db->select() returns new assoc array from database. Many thanks!
  6. Ended up using Zend for emailing in the end. Forget about using PEAR for email until they fix the strict error messages. Seems to be broken at the moment. You can always turn the error messages off with ini_set('display_errors', '0'); but that's probably not the best solution. The Zend mail functionality is very good and not too hard to figure out. http://zendframework.com/manual/en/zend.mail.html
  7. I've been playing with the PEAR mail sending functionality on this example: http://www.blog.highub.com/javascript/javascript-core/make-ubuntu-php-localhost-mail-function-work/comment-page-1/#comment-3059 It actually sends the email and I can get it in my gmail but I get about 50 lines of errors saying: Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mimePart.php on line 307 Strict Standards: Non-static method Mail_mimePart::encodeHeader() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mime.php on line 1316 Strict Standards: Non-static method Mail_mimePart::_explodeQuotedString() should not be called statically, assuming $this from incompatible context in /usr/share/php/Mail/mimePart.php on line 827 Strict Standards: Non-static method Mail::factory() should not be called statically in /opt/lampp/htdocs/sportsite/sendmail.php on line 28 What's up with that? Also do many web hosts have PEAR on them? I'm a bit dubious about relying on it if most web hosts don't actually run it.
  8. Hi, I want to create a forgotten password page, where the user enters in their email address, the script queries the database for that email address, creates a unique ID, stores that unique ID in the database, then emails the unique ID and the User ID off to the user in an HTML link e.g. http://somesite.com/reset-password.php?userId=2&uniqueId=132832189312978312. The reset page would then match the unique ID to the one in the database and let them enter in a new password into the form. Ok so I can do most of that so far except from the emailing to the user. I'm running an Ubuntu Server 10 at the moment as my test server which is on my local network. Do I need to set up a mail server on that for php mailing to work, or can I use some external SMTP for sending? I've had a play round with the PHP mail() function but it won't send anything at the moment. I'll also need some code for when the site is running in the hosted live environment as it will likely use their mail servers. What's the best way to go about doing this? Many thanks!
  9. .htaccess file deny from all Create that in Notepad if on Windows (lets you save files with a . in front) and put that in the /files directory. That will block direct access to the file. PHP can still access the file though. Then all you need to do in your PHP is navigate to the directory where the file is and you should be able to open it using PHP and make it available for download. Well that's what I'd try and do, might be wrong though.
  10. Ok thanks guys. It took a bit of work but I think I've got it working with the bootstrap by following that 2-part tutorial. index.php <?php function __autoload($class_name) { $path = "private/library/" .$class_name. ".php"; if(file_exists($path)) { require_once $path; } else { echo "Class cannot be found: " .$class_name. ".php<br>"; } } $db = new database(); // Initialise the database $lib = new general(); // Make general class available session_start(); // Start new session $page = $lib->getPage(); // Get the page to load require_once($page); getPage() function // Method determines which page should be loaded from the requested PHP page in the URL public function getPage() { // Get just the page name from the URL $url = explode("/", $_SERVER['REQUEST_URI']); $url = array_reverse($url); $page = $url[0]; // If page name isn't in URL or the page is index.php (bootstrap) then set to default homepage if (strpos($page, ".php") === false) { $page = "home.php"; } // If page has GET variables set in URL, remove them so we just get the page name if (count($_GET) > 0) { $page = strtok($page, '?'); } // If the page is index.php (bootstrap) set to default homepage if ($page == "index.php") { $page = "home.php"; } return $page; } .htaccess file in site root RewriteEngine on RewriteBase /mysite/ RewriteRule !\.(js|ico|txt|gif|jpg|jpeg|png|css)$ index.php php_flag magic_quotes_gpc off php_value include_path "./private/library:./private/site:./private/includes" .htacess file in /mysite/private deny from all Basically any request for a file on the website gets redirected to the index.php file which then loads up the database and library methods. The custom getPage() function then finds out what page was requested in the URL e.g. /mysite/home.php and then returns the name of the file "home.php" and loads that file as if you had gone to home.php directly. I needed to put a bit of code in there to remove GET code in the URL e.g. home.php?var=1&msg=2. I tested it with a form and you can still access the $_GET variables now. By putting all the files (except images, css and js) in the private directory the web server stops people accessing them directly. Am I on the right track? Can I just include/require the header and footer manually on each included page now? Or should I be using templates. Things like Smarty etc look too complicated for me and I like doing things manually. Also strange thing is when I access the url of a page directly in the /private folder e.g. /mysite/private/site/home.php then I get an access denied error. But if I access it like this /mysite/site/home.php and pretend the private directory isn't there it can find it/load the page fine. What's happening there?
  11. Not quite sure I understand sorry btherl. Does autoload only have to be loaded once for the whole site, or once per page? If all the code to autoload the libraries is in the index.php then what happens if they first go to say admins.php? Example might help. I was reading this on a website: Where this website wide config file is and how do you tell it to execute? Thanks
  12. function __autoload($class_name) { require_once($_SERVER['DOCUMENT_ROOT'] . '/sportsite/library/' .$class_name. '.php'); } $db = new database(); //Create database object $gen = new general(); $file = new filesystem(); Ok so that code works. But do I have to manually copy/paste that code onto every page of my site now?
  13. Hi, At the moment I have a database class which handles all my db queries and returns results etc. I also have two other classes, general and filesystem. The general class has methods that are used by parts of the site and the filesystem one handles files. To initiate them I have to use the following code: require_once($_SERVER['DOCUMENT_ROOT'] . '/mysite/_private/library/database.php'); $db = new database(); //Create database object require_once($_SERVER['DOCUMENT_ROOT'] . '/mysite/_private/library/general.php'); $gen = new general(); require_once($_SERVER['DOCUMENT_ROOT'] . '/mysite/_private/library/filesystem.php'); $file = new filesystem(); Ok so is there a way to clean this up so I don't have to include all these lines on every page? It seems every time the user goes to a new page they have to open up a new database connection. Ideally it would be good if php scanned my class files on the site and loaded them automatically rather than having to use a long require_once statements on each page. Secondly is there much point in putting the library files in the _private directory? I heard it was a bit more secure by default but that was a while ago. Many thanks!
  14. Cool, thanks for that tip. Got some good optimised code now.  :D
×
×
  • 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.