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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.