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
https://forums.phpfreaks.com/topic/195788-parse-error/
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
https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028515
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
https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028520
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
https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028612
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
https://forums.phpfreaks.com/topic/195788-parse-error/#findComment-1028650
Share on other sites

Archived

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

×
×
  • 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.