Jump to content

[SOLVED] reg script help


Reaper0167

Recommended Posts

here is my reg script...every works good except for giving an error if the username or email already exists. i can't seem to find the problem.

<?php

// connection to your database
include ("connection.php");

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

// define variables from form register form
$username = mysql_real_escape_string($_POST["username"]);
$password = md5($_POST["password"]);
$email = mysql_real_escape_string($_POST["email"]);

// check if username/email is already registered, if so, give error message
$sql="SELECT * FROM $tbl_name WHERE username = '$username' and email = '$email' LIMIT 1";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count == 1)
{
session_start();
$_SESSION['message'] = "The username and/or password is also registered. Please try again.";
header("location: registration.php");
}

// insert user into database
$sql = "INSERT INTO $tbl_name(username, password, email)VALUES('$username','$password','$email')";
mysql_query($sql) or die(mysql_error());

// direct user to login page with a succuess message
session_start();
$_SESSION['message'] = "Thank you for registering $username. You may now log in.";
header("location: http://www.------------.com");

// closes your connection
mysql_close();

?>

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.