marcus Posted October 5, 2006 Share Posted October 5, 2006 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? Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/ Share on other sites More sharing options...
alpine Posted October 5, 2006 Share Posted October 5, 2006 Do you mean adding a message to the user if they already exist in db ? Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104589 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 if a user already exists in the database they cannot register at all, or have to choose a new usernameedit: 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 Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104590 Share on other sites More sharing options...
RyanSmith345 Posted October 5, 2006 Share Posted October 5, 2006 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. Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104594 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 but how do i check w/ sql that it already exists? Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104595 Share on other sites More sharing options...
alpine Posted October 5, 2006 Share Posted October 5, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104597 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 ok, lemme try that Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104599 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 It isnt workingWarning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/neoblob/public_html/inc/do_reg.inc on line 20 Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104601 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 if i post the code could you alter it so it will work? possibly? Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104604 Share on other sites More sharing options...
redarrow Posted October 5, 2006 Share Posted October 5, 2006 [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] Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104608 Share on other sites More sharing options...
alpine Posted October 5, 2006 Share Posted October 5, 2006 [quote author=mgallforever link=topic=110627.msg447561#msg447561 date=1160085805]It isnt workingWarning: 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. ? Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104610 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 yes i did Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104612 Share on other sites More sharing options...
marcus Posted October 5, 2006 Author Share Posted October 5, 2006 Omg, thanks redarrow, it works now, I owe you :) Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104613 Share on other sites More sharing options...
redarrow Posted October 5, 2006 Share Posted October 5, 2006 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 Link to comment https://forums.phpfreaks.com/topic/23116-sql-if-already-exists-in-db/#findComment-104621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.