/    Sign up×
Community /Pin to ProfileBookmark

PHP Membership help.

Hello, I am trying to create a membership system from PHP Freaks. I don’t know how to use phpmyadmin, and create a database and add the following to it:

[quote]

Let’s begin by creating a standard database structure for you to use. First, you may use phpMyAdmin or something that you are familiar with to create your databases. I use phpMyAdmin because it’s fairly easy to use and I don’t have to store any applications or use any command line stuff while on my computer. Simply create your own database and call it whatever you want. Inside that database, run this SQL statement.

[/quote]

[code=php]CREATE TABLE users (
userid int(25) NOT NULL auto_increment,
first_name varchar(25) NOT NULL default ”,
last_name varchar(25) NOT NULL default ”,
email_address varchar(25) NOT NULL default ”,
username varchar(25) NOT NULL default ”,
password varchar(255) NOT NULL default ”,
info text NOT NULL,
user_level enum(‘0′,’1′,’2′,’3’) NOT NULL default ‘0’,
signup_date datetime NOT NULL default ‘0000-00-00 00:00:00’,
last_login datetime NOT NULL default ‘0000-00-00 00:00:00’,
activated enum(‘0′,’1’) NOT NULL default ‘0’,
PRIMARY KEY (userid)
) TYPE=MyISAM COMMENT=’Membership Information’; [/code]

Also, since I skipped this to continue, I am stuck at what to do with this one code I was given. What do I name it and….does it go in another file??

[URL=http://www.phpfreaks.com/tutorials/40/4.php]Link here[/URL]

[QUOTE]

Activating the Membership

This next step is to create a script that based upon the email we have sent the user with their information, we can activate the account by just calling the script. Here’s the script below:

[/QUOTE]

[code=php]<?
/* Account activation script */

// Get database connection
include ‘db.php’;

// Create variables from URL.

$userid = $_REQUEST[‘id’];
$code = $_REQUEST[‘code’];

$sql = mysql_query(“UPDATE users SET activated=’1′ WHERE userid=’$userid’ AND password=’$code'”);

$sql_doublecheck = mysql_query(“SELECT * FROM users WHERE userid=’$userid’ AND password=’$code’ AND activated=’1′”);
$doublecheck = mysql_num_rows($sql_doublecheck);

if($doublecheck == 0){
echo “<strong><font color=red>Your account could not be activated!</font></strong>”;
} elseif ($doublecheck > 0) {
echo “<strong>Your account has been activated!</strong> You may login below!<br />”;
include ‘login_form.html’;
}

?> [/code]

to post a comment
PHP

26 Comments(s)

Copy linkTweet thisAlerts:
@BuezaWebDevFeb 28.2006 — Log into MySQL by opening up a command line window.

type cd mysqlbin [enter]

type mysqld -uroot [enter]

[i]this is assuming your root doesn't have a password[/i]

your display should be like this now:
<i>
</i>mysql&gt;


Copy paste your database script (below)
<i>
</i> CREATE TABLE users (
userid int(25) NOT NULL auto_increment,
first_name varchar(25) NOT NULL default '',
last_name varchar(25) NOT NULL default '',
email_address varchar(25) NOT NULL default '',
username varchar(25) NOT NULL default '',
password varchar(255) NOT NULL default '',
info text NOT NULL,
user_level enum('0','1','2','3') NOT NULL default '0',
signup_date datetime NOT NULL default '0000-00-00 00:00:00',
last_login datetime NOT NULL default '0000-00-00 00:00:00',
activated enum('0','1') NOT NULL default '0',
PRIMARY KEY (userid)
) TYPE=MyISAM COMMENT='Membership Information';


and then press [ Enter ].

Then create a .php file in your localhost called "activate.php".

From this point, you've [1] created your database, and [2] you are ready to have your accounts to be activated.
Copy linkTweet thisAlerts:
@BuezaWebDevFeb 28.2006 — By the way, that tutorial sucks. :p
Copy linkTweet thisAlerts:
@codym43authorFeb 28.2006 — Log into MySQL by opening up a command line window.

type cd mysqlbin [enter]

type mysqld -uroot [enter]

this is assuming your root doesn't have a password

your display should be like this now:


What? I am using PHPMyAdmin that comes with my hosting.....I don't understand what you mean.
Copy linkTweet thisAlerts:
@BuezaWebDevFeb 28.2006 — So you've created the database then? If not, you have to go into your cpanel and create the database there and then add your dbuser to that database.
Copy linkTweet thisAlerts:
@codym43authorFeb 28.2006 — I added the database. Now I am trying to get the registration thing working.

try it out, I get a bunch of crap after I do it...I have the form on the page, the action is "register.php", but I get crap when I hit Join!

http://webdesigner.myfxh.com/register.html
Copy linkTweet thisAlerts:
@DoppleFeb 28.2006 — [code=html]<input name="first_name" type="text" id="first_name" value="<?php echo "$first_name" ?>">[/code]
Try that format in your html.

Do you actually want a value in the text boxes already?
Copy linkTweet thisAlerts:
@codym43authorFeb 28.2006 — No I don't...So nobody knows why I am getting the error??
Copy linkTweet thisAlerts:
@DoppleMar 01.2006 — Just so you know, I can't select the fields with my mouse, I have to tab to them to fill them in. I'm no php expert (think I'm probably in the same boat as you) but I think the method should be "post" for your form and you don't seem to have a php file in your action.
Copy linkTweet thisAlerts:
@BuezaWebDevMar 01.2006 — No I don't...So nobody knows why I am getting the error??[/QUOTE]

<i>
</i>&lt;div id="leftc"&gt;
&lt;form name="form1" method="get" action=""&gt;


Change it to
<i>
</i>&lt;form name="form1" method="post" action="register_action.php"&gt;


in register_action.php
[code=php]
<?php
$firstname = mysql_escape_string($_POST['firstname']);
$lastname = mysql_escape_string($_POST['lastname']);
$emailAddress = mysql_escape_string($_POST['email']);
$username = mysql_escape_string($_POST['username']);

//fill in the code here

// 1. connect to db
// 2. write the query using an INSERT INTO statement
// 3. send that query to the db using mysql_query($query)
?>
[/code]
Copy linkTweet thisAlerts:
@codym43authorMar 01.2006 — Ok, I changed the form. the other code, what is that? Also, I renamed register.php to register_action.php. Dont know if I should have. It still doesn't work though.

[code=php]
<?php
$firstname = mysql_escape_string($_POST['firstname']);
$lastname = mysql_escape_string($_POST['lastname']);
$emailAddress = mysql_escape_string($_POST['email']);
$username = mysql_escape_string($_POST['username']);

//fill in the code here

// 1. connect to db
// 2. write the query using an INSERT INTO statement
// 3. send that query to the db using mysql_query($query)
?>
[/code]

So that goes in register.php, (or as u say, register_action.php?) and where in it?
Copy linkTweet thisAlerts:
@DoppleMar 02.2006 — [code=php]<?php
$firstname = mysql_escape_string($_POST['firstname']);
$lastname = mysql_escape_string($_POST['lastname']);
$emailAddress = mysql_escape_string($_POST['email']);
$username = mysql_escape_string($_POST['username']);

//fill in the code here

// 1. connect to db
// 2. write the query using an INSERT INTO statement
// 3. send that query to the db using mysql_query($query)
?>[/code]


What you'll have to do is something like what's below
[code=php]
//db connect statement here
$result = mysql_query("INSERT INTO yourtable (all, sql, fields, data, should,
go, into) VALUES ('$firstname', '$lastname', '$emailAddress', '$username');");
if ($result) {
echo "<p>Your details have been posted - thanks!</p>";
exit;
} else {
echo "<p>There was a problem with your submission - please try again.</p>";
}[/code]

or something along those lines. You'd also want to put some validation in there, above that code, to make sure email addresses are valid and usernames haven't been taken already.
Copy linkTweet thisAlerts:
@BuezaWebDevMar 02.2006 — Ok, I changed the form. the other code, what is that? Also, I renamed register.php to register_action.php. Dont know if I should have. It still doesn't work though.

[code=php]
<?php
$firstname = mysql_escape_string($_POST['firstname']);
$lastname = mysql_escape_string($_POST['lastname']);
$emailAddress = mysql_escape_string($_POST['email']);
$username = mysql_escape_string($_POST['username']);

//fill in the code here

// 1. connect to db
// 2. write the query using an INSERT INTO statement
// 3. send that query to the db using mysql_query($query)
?>
[/code]

So that goes in register.php, (or as u say, register_action.php?) and where in it?[/QUOTE]


Do you have mIRC?

I can help you out on IRC, step by step and help you with debugging. You can find me on #php at irc.quakenet.org.

By the way, keep the file name the same as register.php. Create a new file called register_action.php and paste the code I posted into register_action.php.
Copy linkTweet thisAlerts:
@codym43authorMar 02.2006 — Some people from another site are helping me also...I made the new file and uploaded it. How do the other files make a difference? And...... I am trying to use register.php as the register page. Isn't working out- www.webdesigner.myfxh.com/register.php

Edit- No I don't have Mirc, only AIM and Yahoo Messenger.
Copy linkTweet thisAlerts:
@DoppleMar 03.2006 — Can you post your whole code for register.php? I'm still having trouble trying to select your text boxes. Once I enter my information and submit it I get the following errors

Warning: main(db.php): failed to open stream: No such file or directory in /home/adidas2/public_html/register_action.php on line 3

Warning: main(db.php): failed to open stream: No such file or directory in /home/adidas2/public_html/register_action.php on line 3

Warning: main(): Failed opening 'db.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/adidas2/public_html/register_action.php on line 3

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/adidas2/public_html/register_action.php on line 52

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/adidas2/public_html/register_action.php on line 53

No database selected
Copy linkTweet thisAlerts:
@SpectreReturnsMar 03.2006 — Which means you're trying to use a database wrapper, but it doesn't actually exist where you think it does, or exist at all.
Copy linkTweet thisAlerts:
@codym43authorMar 03.2006 — I got it to work by adding db.php (duh) but now there is some text that shouldnt be there, on top of it.... I replaced the form with register.php too, so I am using the page:

www.webdesigner.myfxh.com/register.php
Copy linkTweet thisAlerts:
@codym43authorMar 04.2006 — oops..double post sry.
Copy linkTweet thisAlerts:
@DoppleMar 06.2006 — All I got was "This page is currently disabled. Please try again later."
Copy linkTweet thisAlerts:
@codym43authorMar 06.2006 — oh yeah I moved it to another page...one sec..

http://www.webdesigner.myfxh.com/register1.php
Copy linkTweet thisAlerts:
@DoppleMar 07.2006 — I submitted my details and got
Your membership information has been mailed to your email address! Please check it and follow the directions![/QUOTE]
I also received the authentication email. Only problem is when I click the link I get a 502 bad gateway error. What is the code for sending the email?
Copy linkTweet thisAlerts:
@codym43authorMar 07.2006 — it is part of register.php

<i>
</i>&lt;?

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'];


/* 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);



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

if($_POST['submit'] &amp;&amp; (!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! &lt;br /&gt;';
if(!$first_name){
echo "First Name is a required field. Please enter it below.&lt;br /&gt;";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.&lt;br /&gt;";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.&lt;br /&gt;";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.&lt;br /&gt;";
}
include 'register.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 &gt; 0) || ($username_check &gt; 0)){
echo "Please fix the following errors: &lt;br /&gt;";
if($email_check &gt; 0){
echo "&lt;strong&gt;Your email address has already been used by another member
in our database. Please submit a different Email address!&lt;br /&gt;";
unset($email_address);
}
if($username_check &gt; 0){
echo "The username you have selected has already been used by another member
in our database. Please choose a different Username!&lt;br /&gt;";
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 &lt;= 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 = "Registration at Riverfront Christian School!";
$message = "Dear $first_name $last_name,
Thank you for following the directions.

<i> </i>You are now two steps from being able to login.

<i> </i>To activate your account,
<i> </i>please click here: http://www.webdesigner.myfxh.com/activate.php?id=$userid&amp;code=$db_password

<i> </i>Once you activate your membership, you will be able to login
<i> </i>with the following information:
<i> </i>Username: $username
<i> </i>Password: $random_password

<i> </i>Thanks!
<i> </i>The Webmaster

<i> </i>This is an automated response, please do not reply!";

<i> </i>mail($email_address, $subject, $message,
<i> </i> "From: MyDomain Webmaster&lt;[email protected]&gt;n
<i> </i> X-Mailer: PHP/" . phpversion());
<i> </i>echo 'Your membership information has been mailed to your email address!
<i> </i>Please check it and follow the directions!';
}
?&gt;
Copy linkTweet thisAlerts:
@DoppleMar 08.2006 — Hmm. Looks ok. Think the problem may be with activate.php. Can you post that?

By the way, I'd change your code to be something like below. This will stop the code activating unless you hit the submit button.
[code=php]if (isset($_POST['submit'])) {
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 'register.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!
}
}[/code]
Copy linkTweet thisAlerts:
@codym43authorMar 09.2006 — Nope that screws it up. See?
Copy linkTweet thisAlerts:
@DoppleMar 13.2006 — Scrap what I said for the time being but If you could post activate.php...
Copy linkTweet thisAlerts:
@codym43authorMar 18.2006 — [code=php]
<?
/* Account activation script */

// Get database connection
include 'db.php';

// Create variables from URL.

$userid = $_REQUEST['id'];
$code = $_REQUEST['code'];

$sql = mysql_query("UPDATE users SET activated='1' WHERE userid='$userid' AND password='$code'");

$sql_doublecheck = mysql_query("SELECT * FROM users WHERE userid='$userid' AND password='$code' AND activated='1'");
$doublecheck = mysql_num_rows($sql_doublecheck);

if($doublecheck == 0){
echo "<strong><font color=red>Your account could not be activated!</font></strong>";
} elseif ($doublecheck > 0) {
echo "<strong>Your account has been activated!</strong> You may login below!<br />";
include 'login_form.html';
}

?>

<?
session_start();

echo "Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!
You have made it to the members area!<br /><br />";

echo "Your user level is ". $_SESSION['user_level']." which enables
you access to the following areas: <br />";

if($_SESSION['user_level'] == 0){
echo "- Forums<br />- Chat Room<br />";
}
if($_SESSION['user_level'] == 1){
echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";
}

echo "<br /><a href=logout.php>Logout</a>";

?>
[/code]
Copy linkTweet thisAlerts:
@simonetDec 04.2006 — Im working with the PHP Membership System V2.0

http://www.phpfreaks.com/tutorials/65/1.php

Things have gone well so far.

My problem is:

checkuser.php - checks user input from login_form.html.

This pice of code is missing I cannot find it anywhere, while searching I came across this thread.

Please Please Please can anyone help me with this. PLEASE I spent ages following the tutorial and learnt alot. Please could someone post checkuser.php

Thanks, your hopefull and forever greatfull

Simon ?
×

Success!

Help @codym43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...