Jump to content


Check against database.

  • Please log in to reply
3 replies to this topic

#1 habook2

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 17 June 2006 - 01:35 AM

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.

#2 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 17 June 2006 - 01:51 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 habook2

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 17 June 2006 - 04:51 AM

All right. Here's what I have.

<?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");
($name == $dbname && $pass == $dbpass)
{ print "Login Successful"; setcookie ("laplogin", "Logged in", time( ) + 500000);
{ print "Login failed."; } ?>

The if is probably redundant, but still.

#4 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 June 2006 - 11:05 AM

Your queries are wrong, well not wrong but not grabbing the data yet. So heres what your code should be:

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


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users