What's new

Closed Php log in

Status
Not open for further replies.

ribbit

Eternal Poster
patulong po baka alam niyo tong error na ito
TIA
errors:
Warning: Undefined array key "usern" in C:\xampp\htdocs\obs_db\login.php on line 15

Warning
: Undefined array key "passw" in C:\xampp\htdocs\obs_db\login.php on line 16

```


<!DOCTYPE html>
<html>
<head>
<body bgcolor="lightgray">
<meta charset="utf-8">
<title>Log in</title>
<link rel="stylesheet" href="css/signin.css" />
</head>
<body>
<?php
session_start();
include('db.php');
date_default_timezone_set("Asia/Manila");
$date = date("y/m/d h:i:a");
$usern = $_POST['usern'];
$passw = $_POST['passw'];
$_SESSION['admin'] = '';
$_SESSION['user'] = '';
$sql = " SELECT * FROM admin WHERE usern = '$usern' AND passw = '$passw'";
$result = mysqli_query($db, $sql);
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
if($row['usern'] = $usern && $row['passw'] = $passw){
$_SESSION['admin'] = $usern;
header("location: index.php".$_SESSION['admin']);
}
}
}else{
$sql1 = " SELECT * FROM user WHERE usern = '$usern' AND passw = '$passw'";
$result1 = mysqli_query($db, $sql1);
if($result1->num_rows > 0){
while($row = $result->fetch_assoc()){
if($row['usern'] = $usern && $row['passw'] = $passw){
$_SESSION['user'] = $usern;
header("admin\index.php".$_SESSION['user']);
}else{
header("");
}
}
}
}
?>
<div class="form">
<div class="container">
<h1>&nbspSign In</h1>
<p>&nbspPlease fill in this form to create an account.</p>
<hr>
<form action="db.php" method="post" name="login" style="border:10px solid #0000">
<label for="UserName"><b>UserName</b></label>
<input type="text" name="usern" placeholder="usern" required />
<label for="PassWord"><b>PassWord</b></label>
<input type="PassWord" name="passw" placeholder="passw" required />
<p>If you have dont have an account <a href="registration.php" style="color:dodgerblue">Click Here</a>.</p>
<button type="submit" class="signupbtn">Log In</button>
</form>

</div>
</div>
<?php ?>
</body>
</html>

```
 
Solution
Mag e-error talaga yan..BEfore getting the value of POST data you need to make a condition first if the submit buton is clicked.

Code:
if (isset($_POST)){
  //get POST here..
  //get data from database
}

or better use $_SERVER['REQUEST_METHOD'] == 'POST'
Mag e-error talaga yan..BEfore getting the value of POST data you need to make a condition first if the submit buton is clicked.

Code:
if (isset($_POST)){
  //get POST here..
  //get data from database
}

or better use $_SERVER['REQUEST_METHOD'] == 'POST'
 
Solution
Mag e-error talaga yan..BEfore getting the value of POST data you need to make a condition first if the submit buton is clicked.

Code:
if (isset($_POST)){
  //get POST here..
  //get data from database
}

or better use $_SERVER['REQUEST_METHOD'] == 'POST'
This is right. POST data is called already on page load, but no POST data available yet. Kaya i-wrap mo sa condition ung code mo na i-process lang ang pagkuha ng value ng POST data only on POST request.
 
Status
Not open for further replies.

Similar threads

Back
Top