INTRODUCTION TO USER.PHP

Now that your database has been updated with your new field, now we venture into user.php.

When you first open user.php, the first thing that you see is the comments Tammy has left us at the top of the page.

In order to keep myself straight, I usually add a short list of what I've done either directly above or directly below these comments. To make sure you don't mess up your page, hide this list using a comment.

Version #1 -- //

PHP:
  1. // This will make only a single line a comment.  Once you hit enter, your comment has ended.

Version #2 -- /* and */

PHP:
  1. /* This will make everything a comment until you close it.
  2.     This type of comment is great for hiding a large section of code if you seriously have to alter it, but don't want to lose it should something go wrong.
  3.     Just copy it that section and put these comment tags on either side.  If you need the original back, erase your mod and remove the comment tags. */

 

Now, next up is stuff you probably shouldn't mess with since it checks to see if people are logged in and whether they should be there.

 

Starting at about line 133 or so is a spot that says:

PHP:
  1. function main( )

Welcome to the first part of the profile. This is the menu that appears when you click on the "Your Account" link. Here you can add icons to display next to the links, maybe even add another link.

 

PHP:
  1. function stats( )

After that begins the user stats section, which is the first area to add potential mods. Do you want to display person's choice for that new field?

 

The first few lines are all SQL statements that get the person's favorites, so ignore those. Under the include statement that calls timefunctions.php is a bunch of statements that call profile information. You shouldn't have to add anything to those statements.

However, if you added another website field, you should add in the replacement code so it displays properly.

Look closely at the statements until you find a line that begins $website. This line and the one below it are set to check to see if the URL has an http:// in front of it and add it in if it doesn't.

If you want the extra website link to display properly, you're going to have to write a similar statement. But wait! Why write, when you can copy and paste?

Highlight and copy the $website lines and paste them just below the original two lines. Put a couple line breaks above and below it if necessary to keep it separate while you're working on it. Remember to keep the lines intact, including the semi-colons, which tell the server that the statement is over.

 

For the sake of simplicity, pretend you've added a field called "blog" that is intended to store the URL to the user's Weblog. Replace all instances of website with blog.

Next, scroll down to where the results of the stats page is displayed. In php, this is always the output. Once again, find where it says website. Copy, paste, and rename to "blog."

 

But what if you want to add in the results from another field that doesn't require it to become a link, but just to display the data? That's easy. The format is always

PHP:
  1. ".$userinfo['fieldname']."

 

What about an extra instant messenger link? Again, fairly easy. Look at the example for MSN.

It displays the icon of the messenger service and then a statement that looks similar to the format I showed you before. Except in this statement, there's a question mark followed by a repeat of that statement, a colon (:), and then _NONE. What this does is say "If they have an MSN contact, display the information." Otherwise, just return "None."

So if we're adding, say, Jabber it would look like this:

PHP:
  1. <img src=\"images/jabber.gif\" alt=\"Jabber\"/> ".($userinfo['jabber'] ? $userinfo['jabber'] : _NONE)."

NOTE: Remember that if you're using quotation marks in HTML that has been embedded in php, you must precede each one with a backslash ( \ ) to escape them – meaning you have to tell the script to ignore them. Otherwise, you will get an error.

 

PHP:
  1. function editbio ()

Let's move on to the editbio function. This controls the actual edit bio AND registration pages, where your users can create, update, and edit their profile information.

First thing you should notice are lines that look like this:

PHP:
  1. $betareader = ($_POST['betareader'] == "on" ? 1 : 0);

This controls the yes or no type statements, such as betareader, contact, and favorites alert. This tells the script that when the betareader checkbox is checked, it is "on" equals 1 (yes), "off" equals 0 (no). If you've added a yes or no field, add it in now. As usual, just copy, paste, and rename.

 

Before you begin adding too many other things in, let's take a look at SQL statements.

You can leave a response, or trackback from your own site.

Leave a Reply