Jump to content

Archived

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

marcus

SQL If Already Exists In DB

Recommended Posts

Ok, well, I'm trying to make my registration more secure by adding something if the username, email or ip already exists in the database, how would i do this?

Share this post


Link to post
Share on other sites
Do you mean adding a message to the user if they already exist in db ?

Share this post


Link to post
Share on other sites
if a user already exists in the database they cannot register at all, or have to choose a new username

edit: many of my user tend to attempt to register multiple times, and when i view the member list there they are, right next to each other

Share this post


Link to post
Share on other sites
do a

SELECT count(*) FROM users_table WHERE user_name =  . $_POST['username']

I like to do the check with AJAX also on the user name text field blur event so you can inform them before they fill out the rest of the form.

Share this post


Link to post
Share on other sites
but how do i check w/ sql that it already exists?

Share this post


Link to post
Share on other sites
[code]

<?php

$num = mysql_result(mysql_query("select count(*) from users where user = '$user' or email = '$email' or ip = '$ip'"),0);
if($num == 1)
{
  // already exists
}

?>

[/code]

Share this post


Link to post
Share on other sites
It isnt working

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neoblob/public_html/inc/do_reg.inc on line 20

Share this post


Link to post
Share on other sites
if i post the code could you alter it so it will work? possibly?

Share this post


Link to post
Share on other sites
[code]

<?php

$username=addslashes($_POST['username']);
$email=addslashes($_POST['email']);
$ip=addslashes($_POST['ip']);

$query="SELECT * FROM `users` WHERE `username`='$username' or `email`='$email' or `ip`='$ip' "

$result=mysql_query($query);

if(mysql_num_rows($result)){

echo "Sorry but you have a account with us!"

}

?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110627.msg447561#msg447561 date=1160085805]
It isnt working

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neoblob/public_html/inc/do_reg.inc on line 20
[/quote]

Did you change your table- and fieldnames etc. ?

Share this post


Link to post
Share on other sites
Omg, thanks redarrow, it works now, I owe you :)

Share this post


Link to post
Share on other sites
ok mate any time ok your only 14 whale that's young here is a link for you ok,

to help you with any mysql you need to do.

http://www.1keydata.com/sql/sqlandor.html

Share this post


Link to post
Share on other sites

×

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.