Jump to content


Photo

mysql help needed


  • Please log in to reply
2 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 28 July 2006 - 01:43 PM

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.caucas...sus.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.caucas.../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
?>
I don't need your script, I'll try to write it myself

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 28 July 2006 - 02:17 PM

$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.caucas.../test/admin.php' ) ;
}


you could make that nicer with a switch statement but I couldn't be arsed today!
follow me on twitter @PHPsycho

#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 28 July 2006 - 02:27 PM

ok, thanks, I'll try that:)
I don't need your script, I'll try to write it myself




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users