Jump to content

Check against database.


habook2

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/12214-check-against-database/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46563
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46586
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/12214-check-against-database/#findComment-46620
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.