-4

Basically what I need is a php/mysql code to check if a column (username column) is in the same row as the other column (password column) but I'm not sure how to do so, I'm fairly new with working with MySQL. Here's my register code:

<?php

define('DB_HOST', 'localhost');
define('DB_NAME', 'credentials');
define('DB_USER', 'julianbuscema');
define('DB_PASSWORD', '');
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db = mysql_select_db(DB_NAME, $con) or die("Failed to connect to MySQL: " . mysql_error());

function NewUser()
{
    $fullname = $_POST['name'];
    $userName = $_POST['user'];
    $email = $_POST['email'];
    $password = $_POST['pass'];
    $query = "INSERT INTO websiteusers (fullname,userName,email,pass) VALUES ('$fullname','$userName','$email','$password')";
    $data = mysql_query($query) or die(mysql_error());
    if ($data){
        echo "YOUR REGISTRATION IS COMPLETED...";
    }
}

function SignUp()
{
   if (!empty($_POST['user']))
   { 
       $query = mysql_query("SELECT * FROM websiteusers WHERE userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error()); 
       if(!$row = mysql_fetch_array($query) or die(mysql_error())) { 
          newuser(); 
       } else { 
          echo "SORRY...YOU ARE ALREADY REGISTERED USER..."; 
       } 
   } 
} 

if(isset($_POST['submit'])) { 
   SignUp();
}

?>
Naved Munshi
  • 487
  • 1
  • 5
  • 17
Julian
  • 75
  • 1
  • 8
  • Sorry but this is not a question – meda Oct 21 '14 at 04:24
  • `Basically what I need is a php/mysql code` >> [Simple PHP Login](http://stackoverflow.com/a/18971788/342740) – Prix Oct 21 '14 at 04:25
  • *"I have made a register code but I'm not sure of how to use it to login"* - That's like an architect who's drawn up plans for a building, but doesn't know how it's put together or where the back door is; *ironic*. – Funk Forty Niner Oct 21 '14 at 04:40
  • possible duplicate of [Simple PHP SQL login troubleshooting](http://stackoverflow.com/questions/18971570/simple-php-sql-login-troubleshooting) – dimo414 Oct 21 '14 at 05:22
  • Please learn any popular php framework – Yang Oct 21 '14 at 07:12

1 Answers1

0

Use this basic login page:

index.php

<?php
include('login.php');
?>

<form action="index.php" method="POST" id="login-form" >

  <div class="xxxx"><?php echo $error; ?></div>      
  <div class="xxxxx">
        <input type="text" name="username" placeholder="Username" required>
        <input type="password" name="password" placeholder="Password" required>
        <input type="submit" value="Log in" name="login">
    </div>
</form>

login.php

<?php

mysql_connect("hostname","db_username","db_password");
mysql_select_db("dbname");

if(isset($_POST['login'])){

    $username = $_POST['username'];
    $password = $_POST['password'];

    $check_user = "select * from table where username='$username' AND password='$password'";

    $run = mysql_query($check_user);

    if(mysql_num_rows($run)>0){

    header("location: other_page.php"); 
    }
    else {
    $error='Username or password is incorrect!';
    }
}

?>
vas_bar_code
  • 213
  • 1
  • 19