Jump to content

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
?>
Link to comment
https://forums.phpfreaks.com/topic/15886-mysql-help-needed/
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!
Link to comment
https://forums.phpfreaks.com/topic/15886-mysql-help-needed/#findComment-65165
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.