What's new

PHP Log in problem

Status
Not open for further replies.

ribbit

Eternal Poster
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
 
Last edited:
Solution
1648889220361.png

1648889920237.png

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'
 

Attachments

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

Last edited:
Status
Not open for further replies.

Similar threads

Back
Top