Jump to content

Parse error!!!


rainprop

Recommended Posts

Hi...

Im creating a simple login page, and i got a parse error..may i know how to fix it??

 

     
$username = $_POST['username'];
    # make a md5 password.
    $md5_password = md5($_POST['password']);
    
    $query = mysql_query("select * from user where username = "$username" and password = "$md5_password""); 

 

thank u to whoever replies...

Link to comment
Share on other sites

it only created more errors..

 

 

Notice: Undefined index: username in C:\wamp\www\login2.php on line 17

 

Notice: Undefined index: password in C:\wamp\www\login2.php on line 19

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\login2.php on line 23

Wrong Username or Password

Link to comment
Share on other sites

yup, i have already made the connection...

 

login2.php

<?php 
session_start();
require_once 'database.php';

    $username = $_POST['username'];
    $md5_password = md5($_POST['password']);
    
    $query = mysql_query("select * from user where username = '$username' and password = '$md5_password'");
    
    if(mysql_num_rows($query) > 0)
    {
        $result = mysql_fetch_assoc($query);                     
$_SESSION['username'] = $_POST['username'];    
header("location:index.php");      
}

else{
echo "Wrong Username or Password";
}
?>
<form name="back" method="post" action="login.php">
<input type="submit" name="back" id="back" value="Back to Home">

 

index.php

 

<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['username'])){
echo "Welcome ".$_SESSION['username'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
  <input type="submit" name="news" id="news" value="News">
</form>
<?php
}

elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<?php

}else{
?>
<form name="login_form" method="post" action="login2.php">
  <label>
  <input name="user" type="text" id="user">ID<br />
  <input name="pass" type="password" id="pass">Password<br />
  </label>
<input type="submit" name="login" id="login" value="Login">
   </label>
</p>

<?php
}
?>

 

 

Link to comment
Share on other sites

this is code.pls help..the previous one is wrong..

 

login2.php

<?php 
session_start();
require_once 'database.php';

    $username = $_POST['username'];
    $md5_password = md5($_POST['password']);
    
    $query = mysql_query("select * from user where username = '$username' and password = '$md5_password'");
    
    if(mysql_num_rows($query) > 0)
    {
        $result = mysql_fetch_assoc($query);                     
$_SESSION['username'] = $_POST['username'];    
header("location:index.php");      
}

else{
echo "Wrong Username or Password";
}
?>
<form name="back" method="post" action="login.php">
<input type="submit" name="back" id="back" value="Back to Home">

 

index.php

 

<?php
session_start();
require_once 'database.php';
if (isset($_SESSION['username'])){
echo "Welcome ".$_SESSION['username'];
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>
<br /><form name="news" method="post" action="news.php">
  <input type="submit" name="news" id="news" value="News">
</form>
<?php
}

elseif(isset($_SESSION['admin'])){
echo"Welcome ".$_SESSION['admin'];
echo"<br><br>You are logged in as an Admin";
?>
<form name="logout" method="post" action="logout.php">
<input type="submit" name="logout" id="logout" value="Logout">
</form>

<?php
}
?>

 

 

login.php

 

<form name="login_form" method="post" action="login2.php">

  <label>

  <input name="username" type="text" id="username">Username<br />

  <input name="password" type="password" id="password">Password<br />

  </label>

<input type="submit" name="login" id="login" value="Login">

  </label>

</p>

 

Link to comment
Share on other sites

$username = $_POST['username']; 
$query = mysql_query("select * from user where username =\"$username\""); 
if($query["password"] == md5($_POST['password'])) {
// success
} else {
// fail
}

 

don't forget to check datbase.php and make sure the info contained is correct. Check your mysql database and make sure your table user contaisn the correct fields. If the password in the database is saved as md5, you're good, if not, use md5() on $query[password] as well.

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.