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
https://forums.phpfreaks.com/topic/140927-solved-reg-script-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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