Jump to content

Setting up a registry.


jwk811

Recommended Posts

Why do they make everything so hard now-a-days. :o I'm trying to set up user accounts. I am trying to learn how to do this from the tutorial here on phpfreaks and having serious trouble. I'm trying right now to copy the examples through out this tutorial because I wouldn't know how to do these myself. I once I get used to everything I will change some stuff around. I just got past step one today where I had to create the users table on the database and had lots of trouble with that but finally solved all those problems. Now I'm on to the hard part where I have to create the scripts to register and the registry form. And in no suprise got more errors and warnings. I used the same script as in the tutorial exept I had to change the email address and the MySQL connection. This script it what the registry form is directed to and processes all the data into the database and all that stuff. Now before I go on am I just supposed to save this into a notepad on a PHP file put into my FTP client? That's what I did I'm pretty sure that's correct.

Once I directed the form using the form method feature to the register.php file where I have my script a whole bunch of error warnings came up. I will show you the warnings right here and the form and script after it. Please tell me what I did wrong or why this isn't going right for me.

Warnings on the page after the form:

(My connection information)

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/j/w/k/jwk811/html/register.php on line 48

Warning: mysql_query(): A link to the server could not be established in /home/content/j/w/k/jwk811/html/register.php on line 48

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/j/w/k/jwk811/html/register.php on line 50

Warning: mysql_query(): A link to the server could not be established in /home/content/j/w/k/jwk811/html/register.php on line 50

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/j/w/k/jwk811/html/register.php on line 52

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/j/w/k/jwk811/html/register.php on line 53

Warning: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/j/w/k/jwk811/html/register.php on line 103

Warning: mysql_query(): A link to the server could not be established in /home/content/j/w/k/jwk811/html/register.php on line 103
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

The script the form was directed to:

[quote]<?

include 'db.php';

// Define post fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

/* Let's strip some slashes in case the user entered
any escaped characters. */

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);


/* Do some error checking on the form posted fields */

if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
    echo 'You did not submit the following required information! <br />';
    if(!$first_name){
        echo "First Name is a required field. Please enter it below.<br />";
    }
    if(!$last_name){
        echo "Last Name is a required field. Please enter it below.<br />";
    }
    if(!$email_address){
        echo "Email Address is a required field. Please enter it below.<br />";
    }
    if(!$username){
        echo "Desired Username is a required field. Please enter it below.<br />";
    }
    include 'join_form.html'; // Show the form again!
    /* End the error checking and if everything is ok, we'll move on to
    creating the user account */
    exit(); // if the error checking has failed, we'll exit the script!
}
   
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
 
$sql_email_check = mysql_query("SELECT email_address FROM users 
            WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users 
            WHERE username='$username'");
 
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
 
if(($email_check > 0) || ($username_check > 0)){
    echo "Please fix the following errors: <br />";
    if($email_check > 0){
        echo "<strong>Your email address has already been used by another member 
        in our database. Please submit a different Email address!<br />";
        unset($email_address);
    }
    if($username_check > 0){
        echo "The username you have selected has already been used by another member 
          in our database. Please choose a different Username!<br />";
        unset($username);
    }
    include 'join_form.html'; // Show the form again!
    exit();  // exit the script so that we do not create this account!
}
 
/* Everything has passed both error checks that we have done.
It's time to create the account! */

/* Random Password generator. 
http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php

We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/

function makeRandomPassword() {
  $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  srand((double)microtime()*1000000); 
      $i = 0;
      while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($salt, $num, 1);
            $pass = $pass . $tmp;
            $i++;
      }
      return $pass;
}

$random_password = makeRandomPassword();

$db_password = md5($random_password);

// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, 
        email_address, username, password, info, signup_date)
        VALUES('$first_name', '$last_name', '$email_address', 
        '$username', '$db_password', '$info2', now())") 
        or die (mysql_error());

if(!$sql){
    echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
    $userid = mysql_insert_id();
    // Let's mail the user!
    $subject = "Your Membership at MyWebsite!";
    $message = "Dear $first_name $last_name,
    Thank you for registering at our website, http://www.mydomain.com!
   
    You are two steps away from logging in and accessing our exclusive members area.
   
    To activate your membership, 
    please click here: http://www.mydomain.com/activate.php?id=$userid&code=$db_password
   
    Once you activate your memebership, you will be able to login
    with the following information:
    Username: $username
    Password: $random_password
   
    Thanks!
    The Webmaster
   
    This is an automated response, please do not reply!";
   
    mail($email_address, $subject, $message, 
        "From: MyDomain Webmaster<contact@psfunmoney.com>\n
        X-Mailer: PHP/" . phpversion());
    echo 'Your membership information has been mailed to your email address! 
    Please check it and follow the directions!';
}

?> [/quote]

That was the script and for the db.php file I set up another PHP file with my connection information but I'm still not sure if that was the problem or not.

Here is the form I used:

[quote]<form action="register.php" method="POST">
<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q6">First Name</label>
  </td>
  <td valign="bottom">
  <input type="text" size="20" name="first_name" value="<?php echo $first_name; ?>" id="q6">
  </td>
</tr>
</table>

<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q7">Last Name</label>
  </td>
  <td valign="bottom">
  <input type="text" size="20" name="last_name" value="<?php echo $last_name; ?>" id="q7">
  </td>
</tr>
</table>

<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q9">Email Address</label>
  </td>
  <td valign="bottom">
  <input type="text" size="20" name="email_address" value="<?php echo $email_address; ?>" id="q9">
  </td>
</tr>
</table>

<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="bottom" >
  <label for="q8">Desired Username</label>
  </td>
  <td valign="bottom">
  <input type="text" size="20" name="username" value="<?php echo $username; ?>" id="q8">
  </td>
</tr>
</table>

<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="top"  >
  <label for="q10">Information about you:</label>
  </td>
  <td valign="bottom">
  <textarea wrap="soft" cols="30" rows="3" name="info" value="<?php echo $info; ?>" id="q10"></textarea>
  </td>
</tr>
</table>

<table width="400" cellpadding="5" cellspacing="0">
<tr valign="bottom">
  <td width="150" valign="bottom" >
 
  </td>
  <td valign="bottom">
  <input type="submit" name="q1_" value="Submit">
  </td>
</tr>
</table>

</form>[/quote]

I kind of have these steps listed backwards though, lol. But maybe you can see what I did wrong. Thank you VERY VERY much for any information and help. I will appreaciate it very much. And please remember I'm very new to this so a lot of this omplex stuff is hard for me to understand.
Link to comment
Share on other sites

Okay I got rid of the db.php part and just put out the connection data. Then this came up:

Warning: mysql_pconnect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/j/w/k/jwk811/html/register.php on line 7

Fatal error: Call to undefined function: () in /home/content/j/w/k/jwk811/html/register.php on line 9

LOL, now what's the problem with this one?  ???

Would you know how to fix this. It's not the same connection problem as last time is it. Whay may I have done wrong.
Link to comment
Share on other sites

"Can't connect" says it all.  Whatever you're using as connection variables isn't right.

The following is what I use to connect to my database:

[code]
$db_host = "localhost";
$db_login = "xxx"; // your database log-in
$db_pass = "xxx"; // your datbase password
$db_name = "xxx"; // your database name
mysql_connect($db_host, $db_login, $db_pass) or die ("Error: Unable to connect");
mysql_select_db($db_name) or die ("Error: Unable to open the database."); [/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.