GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Aug-2008, 09:57
dirt_diver dirt_diver is offline
New Member
 
Join Date: Aug 2008
Posts: 2
dirt_diver is on a distinguished road

Newbie looking for some basic help PHP


I am trying to create a register.php page on my site and I am getting the error :
Fatal error: Undefined class name 'db' in /home/content/t/r/e/site/html/register.php on line 28

Here is my code:
PHP Code:

<?php 
require_once('source.php'); ?>

<html>
<head>
<title>Register an Account</title>
</head>
<body>

<?php

if (isset($_POST['submit'])) { // if form has been submitted
    /* check they filled in what they supposed to, 
    passwords matched, username
    isn't already taken, etc. */

    if (!$_POST['username'] || !$_POST['passwd'] ||
        !$_POST['passwd_again'] || !$_POST['email']) {
        die('You did not fill in a required field.');
    }

    // check if username exists in database.

    if (!get_magic_quotes_gpc()) {
        $_POST['username'] = addslashes($_POST['username']);
    }

$db_object = DB::connect($datasource, TRUE); //-MY ERROR this is line 28

/* assign database object in $db_object, 

if the connection fails $db_object will contain

the error message. */

// If $db_object contains an error:

// error and exit.

if(DB::isError($db_object)) {
    die($db_object->getMessage());
}

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);


    $query = "SELECT username FROM users WHERE username = '".$_POST['username']."'";
    $name_check = $db_object->query($query);

    if (DB::isError($name_check)) {
        die($name_check->getMessage());
    }

    $name_checkk = $name_check->numRows();

    if ($name_checkk != 0) {
        die('Sorry, the username: <strong>'.$_POST['username'].'</strong>'
          . ' is already taken, please pick another one.');
    }
    
    // check passwords match

    if ($_POST['passwd'] != $_POST['passwd_again']) {
        die('Passwords did not match.');
    }

    // check e-mail format

    if (!preg_match("/.*@.*..*/", $_POST['email']) ||
         preg_match("/(<|>)/", $_POST['email'])) {
        die('Invalid e-mail address.');
    }

    // no HTML tags in username, website, location, password

    $_POST['username'] = strip_tags($_POST['username']);
    $_POST['passwd'] = strip_tags($_POST['passwd']);
    $_POST['website'] = strip_tags($_POST['website']);
    $_POST['location'] = strip_tags($_POST['location']);

    // check show_email data

    if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) {
        die('Nope');
    }

    /* the rest of the information is optional, the only thing we need to 
    check is if they submitted a website, 
    and if so, check the format is ok. */

    if ($_POST['website'] != '' & !preg_match("/^(http|ftp):///", $_POST['website'])) {
        $_POST['website'] = 'http://'.$_POST['website'];
    }

    // now we can add them to the database.
    // encrypt password

    $_POST['passwd'] = md5($_POST['passwd']);

    if (!get_magic_quotes_gpc()) {
        $_POST['passwd'] = addslashes($_POST['passwd']);
        $_POST['email'] = addslashes($_POST['email']);
        $_POST['website'] = addslashes($_POST['website']);
        $_POST['location'] = addslashes($_POST['location']);
    }

    $regdate = date('m d, Y');

    $insert = "INSERT INTO users (
            username, 
            FirstName,
            LastName,
            password, 
            regdate, 
            email, 
            website, 
            location, 
            show_email, 
            last_login) 
            VALUES (
            '".$_POST['username']."', 
             '".$_POST['FirstName']."',
              '".$_POST['LastName']."',
            '".$_POST['passwd']."', 
            '$regdate', 
            '".$_POST['email']."', 
            '".$_POST['website']."', 
            '".$_POST['location']."', 
            '".$_POST['show_email']."', 
            'Never')";

$create = $db_object->query($table);    //perform query

if(DB::isError($create)) {
    die($create->getMessage());
} else {
    echo 'Table created successfully.';

}

$db_object->disconnect();

    
?>

<h1>You have been registered</h1>

<p>Thank you, your information has been added, 
you may now <a href="login.php" title="Login">log in</a>.</p>

<?php

} else {    // if form hasn't been submitted

?>
<h1><a href="http://">Mysite.com</a></h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" cellspacing="0" cellpadding="3">
<tr><td>Username*:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>First Name*:</td><td>
<input type="text" name="FirstName" maxlength="40">
</td></tr>
<tr><td>Last Name*:</td><td>
<input type="text" name="LastName" maxlength="40">
</td></tr>
<tr><td>Password*:</td><td>
<input type="password" name="passwd" maxlength="50">
</td></tr>
<tr><td>Confirm Password*:</td><td>
<input type="password" name="passwd_again" maxlength="50">
</td></tr>
<tr><td>E-Mail*:</td><td>
<input type="text" name="email" maxlength="100">
</td></tr>
<tr><td>Website:</td><td>
<input type="text" name="website" maxlength="150">
</td></tr>
<tr><td>Location</td><td>
<input type="text" name="location" maxlength="150">
</td></tr>
<tr><td>Show E-Mail?</td><td>
<select name="show_email">
<option value="1" selected="selected">Yes</option>
<option value="0">No</option>
</select>
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Sign Up">
</td></tr>
</table>
</form>

<?php

}

?>
</body>
</html>
Last edited by dirt_diver : 03-Aug-2008 at 10:10. Reason: spelling
  #2  
Old 03-Aug-2008, 09:59
dirt_diver dirt_diver is offline
New Member
 
Join Date: Aug 2008
Posts: 2
dirt_diver is on a distinguished road

Re: Newbie looking for some basic help PHP


Also when I signed up here I got an email saying that I have to click a link before registration is complete and then one after the fact saying welcome along with some information...

I want that too, hahaha Anyone got that script laying around??? If not what should I search for?
  #3  
Old 03-Aug-2008, 19:02
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 718
Howard_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Newbie looking for some basic help PHP


I do not know much about OO programming in php (yet)

Did you write this script or copy it from somewhere?
Do you have a 'source.php' ??? What is in it?
Anything that might indicate the declaration of a DB class or other files that may include it?

I googled on this 'Class 'DB' not found' and see lots of info to follow. These kinda makes sense, do they to you?
www.vbulletin.com/forum/showthread.php
archives.free.net.ph/xxx.html

try 'Class DB'
http://pear.php.net/reference/DB-latest/DB/DB.html
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] New script engine: Open Basic (Basic syntax) MKTMK Computer Programming Advertisements & Offers 0 01-Sep-2005 06:13
Basic PHP For Loop Help justinhn MySQL / PHP Forum 1 22-May-2005 19:56
Help this girl!! PHP NEWBIE! soulja90 MySQL / PHP Forum 3 06-Mar-2004 10:35
Grouping data from MySQL with PHP - Newbie question. giobbi MySQL / PHP Forum 12 27-Feb-2004 00:34
PHP in HTML jrobbio Web Design Forum 4 24-Jul-2003 06:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:19.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.