Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

mysql help needed

Recommended Posts

hi,
I'am tyring to make a simple login form. username and password is saved in db, I want to check if the inputed information from form is the same saved in db. here is my code, hope someone can help me..... thanks.

<?php

$link = "http://www.3d.caucasus.net/test/";
$linkShow = "Invalid username or password";

$con = mysql_connect("localhost","3d","password"); // connect to db
if(!$con)
{
  die('Could not connect:'.mysql_error()); // error if not connected
}
mysql_select_db("$3d",$con); //select db
$result = mysql_query("SELECT * FROM password"); // select data form "password"
while($row = mysql_fetch_array($result)) //select data from db and store it in $row
{
if($row == '[user]'&&'[pass]')
{
  header( 'Location: http://www.3d.caucasus.net/test/admin.php' ) ; // correct redirect
}
else
  echo "<a href='".$link."'>".$linkshow;
}
if(!mysql_query($con,$result))
{
  die('Could not connect:'.mysql_error());
}
mysql_close($con); // close connection
?>

Share this post


Link to post
Share on other sites
$user = mysql_escape_string($_POST['user']);
$pwrd= mysql_escape_string ($_POST['pwrd']);

$query = "SELECT * FROM `users` WHERE `username` = '$user' AND `password` = '$pwrd''";
$query = mysql_query($qry);

if (mysql_num_rows($query) == 0)
{
echo "Not recognized";
}
if (mysql_num_rows($query) > 1)
{
echo "Duplicate detection";
// write some code to alert aite admin of problem;
}
if (mysql_num_rows($query) == 1)
{
header( 'Location: http://www.3d.caucasus.net/test/admin.php' ) ;
}


you could make that nicer with a switch statement but I couldn't be arsed today!

Share this post


Link to post
Share on other sites

×

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.