🐘 PHP Log in problem

Status
Not open for further replies.

ribbit

Established
wala nang error code ko pero hind siya dumederetcho sa hmtl ko???
sa login_run.php padin siya hind na pupunta sa html

Code:
<?php
include('connection.php');
session_start();
$usern='';
$passw='';
$usern = $_POST['usern'];
$passw = $_POST['passw'];
$_SESSION['admin'] = '';
$_SESSION['user'] = '';
$user_type='';

if (isset($_POST['submit'])) {
    
    
    $usern=$_POST['usern'];
    $passw=$_POST['passw'];
    $sql = " SELECT * FROM admin WHERE usern = '$usern' AND passw = '$passw'";
    $query=" SELECT * FROM users WHERE usern='$usern' AND passw='$passw' AND user_type='$user_type' ";
    $result=mysqli_query($con,$query);

    while($row=mysqli_fetch_array($result)){
        if($row['usern']==$usern && $row['passw']==$passw && $row['user_type']=='Admin' &&$row['verify_status']=='1'){
            header("Location: admin.html");
        }
        elseif($row['usern']==$usern && $row['passw']==$passw && $row['user_type']=='User' &&$row['verify_status']=='1'){
            header("Location: user.html");
        }
    }
}
else
{
    //walang laman
}
?>

eto naman sa log in page ko

Code:
<?php
include('connection.php');
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Log In</title>
    </head>

<body>
    <form action="login_run.php" method="POST" >
        <table>
            <tr>
            <tr>
                <td>Username</td>
                <td><input type="text" name="usern" placeholder="Username"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type="password" name="passw"placeholder="Password"></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" name="submit" value="Log in"></td>
            </tr>
        </table>
    </form>
</body>
</html>

data base ko naman
Code:
id
user_type
usern
passw
f_name
l_name
pnum
addr
email
created_at
verify_token
verify_status
 
Solution
1648889220361.png
1648889920237.webp
di ko alam kung gagana pero pwedi mo pagtyagaan..Di ko pa natest yan kasi basi lang yan sa na post mo..
1. Check your connection variable
2. Since hindi nakapag run ng maayos yung program due to connection, walang pumasok na result that's why di siya nakapg-execute yung num_rows..
 
Code:
<?php

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'obs');

$con = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);

?>

tama naman po yung variable ko sa connection
 
once na gumamit ka kasi ng strtoupper() function, it converts your string to uppercase to make value or sting convenient to access and for conditional purposes..
1648906462533.png
gawin mong CAPS yan since ang laman ng $user_type ay CAPS letters, parati sa defualt papasok yan kasi nakalagay sa case mo ay 'Admin'
 
Perform necessary debugging.
Ex: instead of executing the header(...) function to redirect, echo mo muna laman ng variables

Code:
$user_type = strtoupper($row['user_type']);
switch($user_type ){
    case 'ADMIN':
      echo $user_type ;
    break;
    defualt:
    echo $user_type ;
}

ikaw an bahala kung anong diskarte gagawin mo. Importante these concerns will contribute to your skills para next time you will have an idea of what to do if you encounter the same situation. Working for it increases your knowledge and skills. Good luck!
 
Perform necessary debugging.
Ex: instead of executing the header(...) function to redirect, echo mo muna laman ng variables

Code:
$user_type = strtoupper($row['user_type']);
switch($user_type ){
    case 'ADMIN':
      echo $user_type ;
    break;
    defualt:
    echo $user_type ;
}

ikaw an bahala kung anong diskarte gagawin mo. Importante these concerns will contribute to your skills para next time you will have an idea of what to do if you encounter the same situation. Working for it increases your knowledge and skills. Good luck!
thank you so much sir ill update you po pag nagawa ko maraming samalamat po talaga

okay na sir salamat ulit
 

Attachments

  • adminlogs.webp
    adminlogs.webp
    17.9 KB · Views: 26
  • adminlog.webp
    adminlog.webp
    17.7 KB · Views: 25
  • userlogs.webp
    userlogs.webp
    17.1 KB · Views: 22
  • userlog.webp
    userlog.webp
    18.6 KB · Views: 28
  • tama.webp
    tama.webp
    67.2 KB · Views: 29
Status
Not open for further replies.

Similar threads

About this Thread

  • 16
    Replies
  • 756
    Views
  • 2
    Participants
Last reply from:
ribbit

Trending Topics

Online now

Members online
1,142
Guests online
1,903
Total visitors
3,045

Forum statistics

Threads
2,293,874
Posts
29,087,195
Members
1,207,986
Latest member
davidsanyal32
Back
Top