Jump to content


Photo

SQL If Already Exists In DB


  • Please log in to reply
13 replies to this topic

#1 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 09:46 PM

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?

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 05 October 2006 - 09:48 PM

Do you mean adding a message to the user if they already exist in db ?

#3 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 09:49 PM

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

#4 RyanSmith345

RyanSmith345
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationFort Collins, CO

Posted 05 October 2006 - 09:56 PM

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.

#5 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 09:57 PM

but how do i check w/ sql that it already exists?

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 05 October 2006 - 09:58 PM


<?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
}

?>



#7 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:00 PM

ok, lemme try that

#8 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:03 PM

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

#9 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:11 PM

if i post the code could you alter it so it will work? possibly?

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 10:15 PM


<?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!"

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 05 October 2006 - 10:18 PM

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


Did you change your table- and fieldnames etc. ?

#12 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:19 PM

yes i did

#13 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:20 PM

Omg, thanks redarrow, it works now, I owe you :)

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 10:26 PM

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....l/sqlandor.html


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users