Jump to content

PHP code help


pepsinator

Recommended Posts

Please help me with this code, its supposed to retrieve the users ID on the database when the user has logged on the blog and allow the user to delete or edit their profile

Here is the code below;

<?php
session_start();

$id = isset($_SESSION['id']);

 if ($row['email'] === $email && $row['password'] === $pass) {
    $_SESSION['id'] = $row['id'];
    $_SESSION['email'] = $row['email'];
    header("location: home.php");
    exit();
}

echo "ID value: " .$id. "<br>";

if (!isset($_SESSION['email'])) {
    if ($row['email'] === $email && $row['password'] === $pass) {
        $_SESSION['email'] = $row['email'];
        header("location: home.php");
        exit();
    } else {
        header("location: login.php");
        exit();
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" cotent="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

    <!--Bootstrap-->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    <!--Font Awesome-->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />

    <title>HOME</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>


<h1>Welcome to the our blog <?php echo htmlspecialchars($_SESSION['email'], ENT_QUOTES, 'UTF-8'); ?></h1>
<br>
<a href="logout.php">Logout</a>
<br>
<br>
<div>
    <a href="edit.php?id=<?php echo isset($_SESSION['id']) ? $_SESSION['id'] : ''; ?>" class="link-dark"><i class="fa-solid fa-pen-to-square fs-5 me-3"></i></a>
    <a href="delete.php?id=<?php echo isset($_SESSION['id']) ? $_SESSION['id'] : ''; ?>" class="link-dark"><i class="fa-solid fa-trash fs-5 me-3"></i></a>
</div>

<!--Boostrap-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</body>
</html>

currently it's giving me that error as shown in the picture

image.thumb.png.a685931c5fe0bf5c72cdb21549238778.png

Link to comment
Share on other sites

Way too many errors!

This line:

$id = isset($_SESSION['id']);

Do you know what it does?

And then this line:

if ($row['email'] === $email && $row['password'] === $pass) 
{
	$_SESSION['id'] = $row['id'];
	....
	....
	....

Do you know what is wrong with it?

Add this to the beginning of your script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

It will enable error reporting.  Set it so '0' once you are done developing any script but not until.

Link to comment
Share on other sites

35 minutes ago, pepsinator said:

Thank you i got it write... managed to fix all my errors and it's running perfectly fine now 

Well, I hope it is just for practice as that code has a lot of security vulnerabilities to it even if you got all the syntax errors ironed out.

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.