Jump to content

supertrucker

Members
  • Posts

    171
  • Joined

  • Last visited

Posts posted by supertrucker

  1. Hello,I have written a custom class that is going to handle all of my CRUD operations for my "user" table. Below is the class:

    <?php 	class UserDb {			const TABLE = "users";		const KEY_ID = "Id";		const KEY_EMAIL = "email";		const KEY_JOIN_DATE = "joinDate";		const KEY_VERIFIED = "verified";		const KEY_LAST_LOGIN = "lastLogin";		const KEY_FIRST_NAME = "firstName";		const KEY_LAST_NAME = "lastName";		const KEY_PASSPHRASE = "passphrase";				private $db = null;		public function __construct() {			$this->db = new PDO(					'mysql:host=' . HOST_NAME . 					';dbname=' . DATABASE_NAME . 					';charset=utf8', DATABASE_USER, DATABASE_PASS			);			$this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);			$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);		}			public function userExists($email) {			$sql = $this->db->prepare("SELECT * FROM " . self::TABLE . " WHERE " . self::KEY_EMAIL . " = :email");			$sql->execute(array(':email' => $email));			$row_count = $sql->rowCount();			if ($row_count > 0) { return true; }			else { return false; }		}				public function insertUser($user = null) {			if (is_null($user)) { $user = new User(); } 		}			}	?>

    When I run this, I get:

    Fatal error: Using $this when not in object context in /media/mypassport/var/www/jcbook/include/classes/class.UserDb.php on line 28
    Can anyone tell me what I've done wrong? I've never worked with classes in php before.Thank you in advance!
  2. Also, since I couldn't tell if you're doing so in your code or not already, you could encrypt your users passwords using MD5. Check it out on www.php.net and type md5 into the functions search box. That's what I use for encryping my users passwords, then you can use a simple check to see if a users password is correct, but their real password is actually an MD5 hash string stored in your database. Using MD5 for that sort of application is relatively easy.Peace,Supertrucker :)

  3. Well, I can't speak for everybody, but I know that I would use it. Most cellular companies offer low cost internet packages for unlimited downloading nowadays. I use it quite frequently actually, and have made the mobile internet the basis for my site. If you're curious about what's really going on in the wireless world, have a look around! Most of the major networks, newspapers, and major web sites have realized the importance of the mobile web in their publications and have put out mobile versions of their sites. So obviously I'm not the only mobile user, or they wouldn't be making any money doing so! I just thought a mobile version of w3schools forums would become a valuable asset for us mobile programmers, and I can't think it would be that difficult to implement. I've already started putting together a WAP site, and when I started this a month or two ago, I knew nothing about web page building/programming.Peace yall!Supertrucker, :)

  4. Just a suggestion. I know that W3Schools has a couple things that you could view from a mobile device, but how about mobilizing these forums? I find these forums a great resource, and I would love to see them mobilized, so I could read/respond/add posts on the go.Peace,Supertrucker :)

  5. Thank you, that worked beautifully! Was rackin' my brains out with that one, most of the stuff I need to do I can find in the tutorials, but every so often, I work myself into a corner, and can't figure a way out!Thanks a bundle,Supertrucker :)

  6. Maybe somebody here can give me an idea of what I am doing wrong. I have a form that posts to itself to validate. The part of the form that I'm having trouble with is this:

    Home<input type="checkbox" name="tags" value="home" /><br />Horoscopes<input type="checkbox" name="tags" value="horoscopes" /><br />Language<input type="checkbox" name="tags" value="languages" /><br />Law<input type="checkbox" name="tags" value="law" /><br />Local<input type="checkbox" name="tags" value="local" /><br />

    The idea with having the "name" attributes the same is that when the form is validated, the selected values could be plugged into an array. My dillemma is, how do I retrieve these values into an array?? I figured I could just use this code:

    $tags = $_REQUEST['tags'];

    But it's not working, the $tags variable is only returning one of the selected values, but I can see from passed URL that all of the selected checkboxes were passed along correctly. How do I use PHP to retrieve multiple values from a POST/GET form that have the same name, as in the code up above?Thanks for your help,Supertrucker :)

  7. Not that im a 100% expert at PHP but try to switch the ' and the " like thisecho "<a href='descrip.php?accountnum=$accountnum'>";This might let the $ be called not sure if that fixes but at least I tryed :).
    If that doesn't work, you could always to this too:
    echo "<a href='descrip.php?accountnum=".$accountnum."'>";

  8. Here's what I want, an SQL database that I can use to see what state somebody is in, via their zip code. I would hate to have to program these in myself as there are virtually HUNDREDS of US zip codes out there. I could really use some advice from somebody on this one!Thanks,Supertrucker :)

  9. To answer my own question again, for others that are interested in this topic, WordPress uses a very simple password encyption process, utilizing the md5() function in php. Here's an example using the md5() function straight from php.net:

    <?php$str = 'apple';if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {   echo "Would you like a green or red apple?";   exit;}?>

    I don't entirely understand the underlying purpose of the md5() function, but the above code is enough for somebody to make use of their WordPress user database in their applications. If anybody can give me a better explanation of what the md5() function is really for, I'd like to know!----------------------WordPress uses MySQL to store it's user data. The users are stored in a table called wp_users. Here are the column fields that are in the wp_users table:

    1. user_login
    2. user_pass
    3. user_nicename
    4. user_url
    5. user_registered
    6. user_activation_key
    7. user_status
    8. display_name

    If you don't yet have WordPress installed on your server, you can get it from www.wordpress.com. Installation is a snap, and it's well worth it if you want a good blogging solution for your website. It's 100% free, and there are tons of free plug-ins available for it.I hope this helps somebody out!Regards,Supertrucker :)

  10. I have installed Wordpress on my server and was wondering if anybody could give me any advice. I would like to use the the same logons that wordpress uses for my website. In other words, I would like users to be able to create one account that they can use to access the wordpress portion of my web site, and the rest of my web site. Wordpress encrypts the passwords, and I don't even want to start taking apart the wordpress code to figure out what they do. If anybody has any advice, it would be greatly appreciated!Regards,Supertrucker :)

  11. You're me, eight months ago. No better way than trial&error. I'm fairly new at php too (as in 'no guru').Good luck.
    Thanks, I need it! Now I need to figure out how to create a script that will allow only specific users to logon for administrative functions.
  12. Cool, thanks. And can variables from the main script be accessed in the called function still, by declaring them global in the called function? In other words do the included functions act as if they were coded into the main script? Thanks again and in advance!Supertrucker :)

    you can do something like this have two seperate files we call one page.php and another called functions.php. We will start with the functions page which as you can assume will have all your functions. and will look like this.functions.php
    <?phpfunction somefunction($varaible,$varaible){code here.....code here......code here.....return $varaible}?>

    Okay then on to calling the function from another php page in this case it will be called from our page.php.page.php

    <?php include $_SERVER['DOCUMENT_ROOT'].'/functions.php'; <-------- this includes your functions$variable = somefunction($variable1,$variable2);?>

    The include keyword allows you to include the functions.php page for use on this page. It must be on every page you want to use the functions.Next i used $_SERVER['DOCUMENT_ROOT'].'/functions.php'; as a personal prefence this makes it portable on any server i upload this script to. You can alternativly just do:include '/functions.php';Then the next line of code is calling our function passing $variable2 and $variable2 as arguments for the function to use then storing it into our a variable called $variable.And that is basicly it to calling a function from a diffrent php page.

  13. I hope that clears it up a bit. But if your just learning you might want to get the basic down before you dive into classes and it should make more sense.
    I appreciate it a lot! I am still learning, but I feel I already the grade school stuff down, I'm just trying to read a high school level book in 6th grade! But really, your explanation did help. I kind of understood what classes were, as I've now implemented a mail function into my code using a mail-class I downloaded. I just didn't understand the code that called it, it makes a lot more sense now!Thanks again,Supertrucker :)
  14. This is a useless topic, but I figured I'd give some of you experienced php'ers a laugh.Is it possible to write code in php without generating at least one script error? I've been playing around in PHP for about a month or two now and have not yet found that to be the case!Peace,Supertrucker :)

  15. Thank you, I will give that a shot!Supertrucker :)

    Depends on what u want to pass thru the script... i just use include_once "file.php";but thats bc its just there all the time..you chould use get function like : if($_GET[theget]){$get=$_GET[theget] -Kristian_C
  16. Sorry about the questions one after another, inquiring minds want to know!Can somebody explain to me what this code means? I'm still learning here, and I'm trying to take apart a mail script I downloaded, so i can figure out how to use it correctly, but the examples use this:

    $pop3 = new POP3; //	 <------------------- What does this mean???// Get office status $status = $pop3->get_office_status();   // <-------------- and what does this mean/do???

    Thanks for your help!Supertrucker :)

  17. To answer my own question, after much digging on the internet I found a website with some good examples. There's a class available for download that has a lot of functions I was looking for. If other people are reading this and need pop3 in their applications, here's where I found a good example:www.phpit.netThe downloadable class allows you to read email off of a pop server.All you have to do is download a class and install it on your server. The examples do a fairly good job of walking you through the process. I hope this helps somebody! Took me forever to dig useful stuff out of all the useless crap online!Supertrucker :)

  18. I created a php page that has a form that posts back to the same page, index.php. However, if someone clicks the browser reload button on the "Thank you for submitting!" page, the data is resubmitted. As long as they sit there and keep hitting reload, it will keep resubmitting. I tried the unset() function, but that doesn't actually clear the data from the browser bar that get's reloaded. I pass the data from the original form to the submit page using the "get" attribute. Would changing it to "post" deliver me from evil!? Simply putting a note, I'm afraid, on the web form that says "submit only once" is just asking for trouble! Help!Supertrucker :)

×
×
  • Create New...