![]() |
PHP/SQL - Printable Version +- 2DWorlds Forums (http://2dworlds.buildism.net/forum) +-- Forum: Off Topic (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=5) +--- Forum: Programming (http://2dworlds.buildism.net/forum/forumdisplay.php?fid=30) +--- Thread: PHP/SQL (/showthread.php?tid=7980) Pages:
1
2
|
PHP/SQL - Dignity - 08-12-2011 I have two questions about PHP+SQL.
By "equals something" I mean something like Code: if Pass='$psw' Only in SQL. RE: PHP/SQL - Chaos - 08-12-2011 I don't know much SQL, but why don't you make a variable for the SQL, then check it like: [lua] <?php $okay = TRUE; $sql = "SQL HERE"; if $sql == "$sql { $okay = FALSE; } ?> [/lua] That may have errors, I just did it off the top of my head. But it may work. RE: PHP/SQL - Dignity - 08-13-2011 Let me re-state my question. I have a login system, and for login, how do I check if the input equals the data? RE: PHP/SQL - Chaos - 08-13-2011 Oh that's easy! (password1 is your password, password2 is the one where you confirm it) [lua] if($password1 != $password2) { header('Location: register.php'); } if(strlen($username > 30) { header('Location: register.php'); } [/lua] By the way, I would add in an error message. But that's how you do it. RE: PHP/SQL - Dignity - 08-13-2011 But, password2 is in a database? RE: PHP/SQL - Chaos - 08-13-2011 You can put it in there if you want. But I just check it right when they load the page. Just store there hashed password in the database. RE: PHP/SQL - Dignity - 08-13-2011 I do not understand. Code? RE: PHP/SQL - Chaos - 08-13-2011 Okay, I put the passowrd1 in the database (hashed of course) BUT When they fill out a form: [lua] <html> <!--Form to register--> <form name="register action="register.php" method="post"> Username: <input type="text" name="username" maxlength="30" /> Password: <input type="password" name="password1" /> Password Again: <input type="password" name="password2" /> <input type ="submit" value="Register" /> </form> </html> [/lua] As you can see I have 'Password' (password1) and 'Password Again' (password2) then, when they hit register, it sends username and password, and ID in the database. NOT password2. Password2 is checked when they register ONLY. Why would you need it it in the database. Just check it when they load the page. RE: PHP/SQL - noob007 - 08-13-2011 He's asking how to get a password from a SQL database. Assuming you have a SQL database connection, use this query: [lua] $result = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."' AND password = '".hash('sha256',$_POST['password'])."'"); if (mysql_num_rows($result)) { // success } else { // fail } [/lua] Remember to hash your password. In the example I used sha256. RE: PHP/SQL - Dignity - 08-13-2011 I'ts not working http://virtualscope.x10.mx/Account/cookie.php Source: Code: <?php |