Jump to content

Checking If $user & $pass = " "


Shaned145

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278344
Share on other sites

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')");

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278346
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278349
Share on other sites

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".

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278350
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278357
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278384
Share on other sites

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

?>

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278973
Share on other sites

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

}

Link to comment
https://forums.phpfreaks.com/topic/56344-checking-if-user-pass/#findComment-278987
Share on other sites

Archived

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

×
×
  • Create New...

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.