Shaned145 Posted June 20, 2007 Share Posted June 20, 2007 Ok, Im obviously not doing this right. lol I need some help with my script: if !( $user=="" || $pass==""); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); It wont load up my page when I try to run it with this in my page, what am I doing wrong? It checks my text boxes to see if the user and pass equals a blank input when the person clicks on the submit button, and if it does, then it does nothing. Please, any help is appreciated. Quote Link to comment Share on other sites More sharing options...
liam1412 Posted June 20, 2007 Share Posted June 20, 2007 Do you want to input the username and pass into db unless it is blank???? Not to sure what you mean by your question. Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 20, 2007 Share Posted June 20, 2007 Remove the semi-colon from the end of the first line. Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 if !( $user=="" || $pass==""); The exclamation mark means doe not equal "". I want it so the user cant enter in a blank input on either text boxes. Then the || means or so neither the username nor password can remain blank. So like if I put, "" as the username or password, that it does not enter it. But if I put in say "Shaned123" as the user and "tacos" for the pass, then it adds it in my db. Quote Link to comment Share on other sites More sharing options...
lewis987 Posted June 20, 2007 Share Posted June 20, 2007 you need this code: if ( $user != "" || $pass != ""){ mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } rather than: if !( $user=="" || $pass==""); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 Remove the semi-colon from the end of the first line. Nope, that doesnt work either. Any other suggestions? Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 you need this code: if ( $user != "" || $pass != ""){ mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } rather than: if !( $user=="" || $pass==""); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); Thanks I'll try it out. I new there shouldve been a brackets in there somewhere. Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 20, 2007 Share Posted June 20, 2007 you need this code: if ( $user != "" || $pass != ""){ mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } rather than: if !( $user=="" || $pass==""); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); Actually he will want to use && instead of || if you write it like that. "If $user is not empty AND $pass is not empty, THEN put them in the database". Quote Link to comment Share on other sites More sharing options...
lewis987 Posted June 20, 2007 Share Posted June 20, 2007 never seen that one this is the new code then: if ( ($user !="") && ($pass !="")); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 20, 2007 Share Posted June 20, 2007 never seen that one this is the new code then: if ( ($user !="") && ($pass !="")); mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } You've replaced the semi-colon again! So the IF statement will do nothing and the mysql function will always run regardless. Quote Link to comment Share on other sites More sharing options...
lewis987 Posted June 20, 2007 Share Posted June 20, 2007 god damn if ( ($user !="") && ($pass !="")){ mysql_query("INSERT INTO users (id, sn, pw) VALUES ( '$idhigh + 1', '$user', '$pass')"); } Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 LOL! Haha, ok, I will be sure to update this code again. Haha! Also, how do I check to see if the username is already taken? Quote Link to comment Share on other sites More sharing options...
lewis987 Posted June 20, 2007 Share Posted June 20, 2007 put the field username as unquie. i dont know the code to check with PHP off-hand Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 Ok so I set it as unique, and it doesnt add another username in my table if its taken. But does anyone know how to make it so if the username is taken, that it redirects them to a page where it would say "ERROR: The username has already been registered"? Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 20, 2007 Share Posted June 20, 2007 Something like: $query = "select * from users where sn='$user'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0 { header("Location:error.php"); } where error.php is the page that handles that eventuality. Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 Something like: $query = "select * from users where sn='$user'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0 { header("Location:error.php"); } where error.php is the page that handles that eventuality. Hmmmm, I cant seem to get it working. I made an error.php page but it doesnt show. Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 20, 2007 Share Posted June 20, 2007 Well, what code have you written, what does it do and what error messages are displayed if any? The code sample I gave was just an example of how to do it, something for you to base your solution on not to take as being a fully working script! Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 20, 2007 Author Share Posted June 20, 2007 LOL! Sorry, Im tired. Its friggin' 4:06am where Im at. Anyways, I will write up something and post some more questions if I come across any errors or such. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 21, 2007 Author Share Posted June 21, 2007 Ok, now heres another question of mine. How do I check to see if the password is correct? Quote Link to comment Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 What are you trying to do? It is not obvious from your examples and you seem to be lacking any kinsd of actual question. Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 21, 2007 Author Share Posted June 21, 2007 Im trying to make a register script and a login/logout script. Quote Link to comment Share on other sites More sharing options...
trq Posted June 21, 2007 Share Posted June 21, 2007 To check to see if a username / password combination is correct (valid for login) you would use something like.... <?php if (isset($_POST['uname']) && isset($_POST['upass'])) { $uname = mysql_real_escape_string($_POST['uname']); $upass = mysql_real_escape_string($_POST['upass']); if ($result = mysql_query("SELECT uname,upass FROM users WHERE uname = '$uname' && upass = '$upass';")) { if (mysql_num_rows($result)) { // username / password combination valid. } else { // username / password combination invalid. } } } ?> Quote Link to comment Share on other sites More sharing options...
Shaned145 Posted June 21, 2007 Author Share Posted June 21, 2007 Thanks. I will get right to adding that to my script. If I have any problems I will be sure to post my full script up again and see if anyone can help. Thanks thorpe! Quote Link to comment Share on other sites More sharing options...
corbin Posted June 21, 2007 Share Posted June 21, 2007 I don't know if your question is still lingering, but to check if something is in a table you just do: SELECT field FROM table WHERE field = data Example: $q = mysql_query("SELECT uname FROM users WHERE uname='".addslashes($_POST['uname']."'"); if($q && mysql_num_rows($q) < 0) { //user doesn't exist } else { //user exists } 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.