Jump to content

Register logic


GameYin

Recommended Posts

Ok so I'm trying to understand sessions..I'm going to hand write a register script RIGHT HERE, please point out anything you notice.

 

----DO NOT WORRY ABOUT SECURITY----

Here is my database SQL..

 

CREATE TABLE users (
id INT(11) NOT NULL AUTO_INCREMENT,
username VARCHAR(30) NOT NULL,
password CHAR(40) NOT NULL,
email VARCHAR(70),
active CHAR(32),
PRIMARY KEY(id)
); 

 

 

Register.html

 

<html>
<head>
<title>register</title>
</head>
<body> 
<form action="register.php" method="post">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="text" name="email" />
</form>
</body>
</html>

 

register.php

 

<?php
$host=localhost;
$user=gameyinc;
$pass=******;
$DB=gameyinc_members;
$table=users;

$connect = @mysql_connect ($host, $user, $pass) or die ('Could not connect to MySQL because ' . mysql_error());

@mysql_select_db ($DB) OR die('Could not select the database because ' . mysql_error() );  

$querycheck = "SELECT username FROM users WHERE username = '$user'";
       $resultcheck = @mysql_query($querycheck);
       $num = @mysql_num_rows($resultcheck);
       
       if ($num> 0) {
           echo '<font color="red">The username you have chosen has already been taken, please try again.</font>';
       } else {
           $username = $_POST['username'];
       }
   } else {
       echo '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
   } 
$password = $_POST['password'];
$email = $_POST['email'];

$query = "INSERT INTO $table (username, email, password) VALUES ('$username', '$email', '$password')";

       $result = @mysql_query($query);
       
       if (mysql_affected_rows() == 1) {
           echo '<h3>Thank You!</h3>
           You have been registered as $username.';
       } else {
           echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
       } 
?>

 

Assuming the user won't try to bypass anything, and they enter everything correctly, will this script work?

Link to comment
Share on other sites

You never define $username before you do your query to check if it's already taken. Instead you use the variable $user which is defined for your database connection.

 

<?php
$username = $_POST['username'];
$querycheck = "SELECT username FROM users WHERE username = '$username'";

Link to comment
Share on other sites

pocobueno1388, do I just need to change the spot I define the variable?

 

To everyone else, I just wrote this in homeroom, I'm trying to stay away from free script stuff and write my own. Soon I will be moving onto a session login thing based off of this.  :D :D

Link to comment
Share on other sites

HAHA, wtf?

 

/../resend.php

 

 

Ok, so your activation email didn't get sent? DAMN S**T C*H(#@ ((@J no, stop swearing, put that bottle down. You don't need it. We need each other. I'm here to resend your email, so enter your email address, and I will send the validation link to that email, provided you have registered ofcourse, if you are trying to hack me, what a sad guy, taking advantage of my emotions like that... jeez.
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.