habook2 Posted June 17, 2006 Share Posted June 17, 2006 I need a script in which $a will be checked against column A, and if a row exists where $a exists in column A, it moves on to do the same thing with $b and column B. If successful, print "Successful" and write a cookie, else print "Unsuccessful". In case you haven't guessed, this is for a login. Quote Link to comment https://forums.phpfreaks.com/topic/12214-check-against-database/ Share on other sites More sharing options...
.josh Posted June 17, 2006 Share Posted June 17, 2006 we don't write scripts for people here. we help them with problems with the scripts they are working on. furthermore, i'd say a good 75% of threads here contain the exact thing you are looking for, be it actual posts about it, or just included in the script they are trying to get help on. try doing a search before posting a question. Quote Link to comment https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46563 Share on other sites More sharing options...
habook2 Posted June 17, 2006 Author Share Posted June 17, 2006 All right. Here's what I have.[code]<?php $name = $_POST['name']; $pass = $_POST['password']; $connid = mysql_connect ('localhost' , 'DBUSER' , 'DBPASS'); mysql_select_db ("laughsap_jokes"); $dbuser = mysql_query ("SELECT username FROM users WHERE username LIKE $name WHERE password LIKE $pass") or die("Login failed."); $dbpass = mysql_query ("SELECT password FROM users WHERE username LIKE $name WHERE password LIKE $pass");if($name == $dbname && $pass == $dbpass){ print "Login Successful"; setcookie ("laplogin", "Logged in", time( ) + 500000);}else{ print "Login failed."; } ?>[/code]The if is probably redundant, but still. Quote Link to comment https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46586 Share on other sites More sharing options...
wildteen88 Posted June 17, 2006 Share Posted June 17, 2006 Your queries are wrong, well not wrong but not grabbing the data yet. So heres what your code should be:[code]<?php$connid = mysql_connect ('localhost' , 'DBUSER' , 'DBPASS');mysql_select_db ("laughsap_jokes");// make sure you escape any user input$name = mysql_real_escape_string($_POST['name']);$pass = mysql_real_escape_string($_POST['password']);// select the username and password that match $name and $pass limit the query by 1$sql = "SELECT `username`, `password` FROM users WHERE `username`='$name' AND `password`='$pass' LIMIT 1";$result = mysql_query ($sql, $connid) or die("Query failed");// check that the query returned 1 result, if it did its a successful login!if(mysql_num_rows($result) == 1){ setcookie ("laplogin", "Logged in", time() + 500000); echo "Login Successfull!";}else // not successful!{ echo "Login failed.";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46620 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.