kellz Posted November 11, 2007 Share Posted November 11, 2007 hey people! err it will probably look very very stupid to anyone that knows SQL but yea here is my failed attempt: INSERT INTO `users` IF NOT EXIST( `loginName` , `createDate` , `password` , `email` ) VALUES ( 'Kelz', '11.12.07', MD5( 'hello' ) , '', '', 'lala@yahoo.com' ) I was trying for ages and searching google but to be honest I'm not really sure what I'm looking for how do I insert this data if it's not already there? ??? Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 11, 2007 Share Posted November 11, 2007 You definitely don't want to do it like that. There is no way to guarantee that every single person who will register has a different password and the createDate I am assuming it's the Day they register, what if two people register on the same Day? Here's an excerpt for a sign in file I made a while ago... if (empty($_POST['mem_dname'])) { die('You didn\'t enter a Display name.'); } else { $mem_dname = mysql_real_escape_string($_POST['mem_dname']); } $query = mysql_query("SELECT * FROM `gs_mem` WHERE `mem_dname` = '".$mem_dname."'"); $fetch = mysql_fetch_object($query); if($fetch->mem_dname == $mem_dname) { die('The Display name you have chosen is already in use.'); } Quote Link to comment Share on other sites More sharing options...
eXeCuTeR Posted November 11, 2007 Share Posted November 11, 2007 $query = mysql_query("SELECT * FROM `users`") or die(mysql_error()); while( $row = mysql_fetch_array($query)) { $loginName = $row['loginName']; $email = $row['email']; if ("Kelz" == $loginName || "lala@yahoo.com" == $email) /* You can add: md5('hello') == $password || $createDate = "11.12.07" but think about it, if 2 users have registered on the same date and with the same password, you don't want it to block 1 of em because he chose the same password or registered on the same date the other one did. if you still want it to be like this, also add $password = $row['password']; and $createDate = $row['createDate']; */ echo "loginName::Kelz already exists OR email::lala@yahoo.com is already in use."; /* **** OR : **** // (same thing, just look it it) if("Kelz" == $loginName) echo "loginName:: Kelz already exists"; if("lala@yahoo.com == $email) echo "email::lala@yahoo.com is already in use."; else { // Insert values... mysql_query("INSERT INTO `users` (`loginName`, `createDate`, `password`, `email`) VALUES ('Kelz', '11.12.07', md5('hello'), 'lala@yahoo.com'")); // BTW, your query was wrong -> after md5('hello') you typed ' ' and then ' ' again which is wrong - SQL thinks it's another value. // Look at the query I typed, this one works. } } If you seem that the code I typed is really long - it's not, I just typed a lot of comments to explain you things, lol. Quote Link to comment Share on other sites More sharing options...
kellz Posted November 11, 2007 Author Share Posted November 11, 2007 yay it works! thanks you very muches! excuse my weird words i only type like that when I'm hyper/happy or both :-\ Quote Link to comment Share on other sites More sharing options...
eXeCuTeR Posted November 11, 2007 Share Posted November 11, 2007 May I ask what method did you choose? Mine's or his? Quote Link to comment Share on other sites More sharing options...
kellz Posted November 11, 2007 Author Share Posted November 11, 2007 kinda used both^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.