Jump to content

check multi


chriscloyd

Recommended Posts

heres my problem
im creating a script so a person can not register an account from the same ip or have the same username or same email as any other users so heres the problem i created the script but it seems to just skip right over it even tho im using the same info i already registered with

heres my first page
[code]
<?php
session_start();
error_reporting(E_ALL);
include("functions.php");
//connect to mysql
mysql_connect('*****','******','******');
mysql_select_db('******');
//register begins
//define vars
$first = $_POST['First_Name'];
$last = $_POST['Last_Name'];
$username = $_POST['Username'];
$password = md5($_POST['Password']);
$email = $_POST['Email'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$key = $_POST['key2'];
$sc = sha1(md5($_POST['key1']));
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$ip = $_SERVER['REMOTE_ADDR'];
check_mulit($ip,$email,$username);
?>
[/code]

then heres my function
[code]
<?php
//connect to mysql
mysql_connect('*****','******','******');
mysql_select_db('******');
//check multi
function check_multi($i,$e,$u) {
$check_i = mysql_query("SELECT * FROM users WHERE ip = '$i'");
$check_e = mysql_query("SELECT * FROM users WHERE email = '$e'");
$check_u = mysql_query("SELECT * FROM users WHERE username = '$u'");
$i_status = mysql_num_rows($check_i);
$e_status = mysql_num_rows($check_e);
$u_status = mysql_num_rows($check_u);
if ($i_status > 0) {
$error = '-You already have an account on this ip address';
header("Location: ../?page=Register&error=$error");
}
if ($e_status > 0){
$error = '-The email address '.$email.' is already registered';
header("Location: ../?page=Register&error=$error");
}
if ($u_status > 0){
$error = '-The username '.$username.' is already taken';
header("Location: ../?page=Register&error=$error");
}
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32278-check-multi/
Share on other sites

you need to return something from your function

I would do something like

[code]
<?php
function check_multi($i,$e,$u) {
$return_value = true;
$check_i = mysql_query("SELECT * FROM users WHERE ip = '$i'");
$check_e = mysql_query("SELECT * FROM users WHERE email = '$e'");
$check_u = mysql_query("SELECT * FROM users WHERE username = '$u'");
$i_status = mysql_num_rows($check_i);
$e_status = mysql_num_rows($check_e);
$u_status = mysql_num_rows($check_u);
if ($i_status > 0) {
$error = '-You already have an account on this ip address';
header("Location: ../?page=Register&error=$error");
$return_value = false;
}
if ($e_status > 0){
$error = '-The email address '.$email.' is already registered';
header("Location: ../?page=Register&error=$error");
$return_value = false;
}
if ($u_status > 0){
$error = '-The username '.$username.' is already taken';
header("Location: ../?page=Register&error=$error");
$return_value = false;
}
return $return_value;
}
[/code]

Then on the Actual code
Something like
[code]
<?php
if(check_mulit($ip,$email,$username)){
echo "Everything is fine, lets add this information
}else{
echo "DEGUB_TEXT: An error has occured, the script should have forwarded.
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/32278-check-multi/#findComment-149830
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.