pepsinator Posted April 20, 2023 Share Posted April 20, 2023 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 Quote Link to comment https://forums.phpfreaks.com/topic/316164-php-code-help/ Share on other sites More sharing options...
ginerjm Posted April 20, 2023 Share Posted April 20, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316164-php-code-help/#findComment-1607523 Share on other sites More sharing options...
pepsinator Posted April 21, 2023 Author Share Posted April 21, 2023 Thank you i got it write... managed to fix all my errors and it's running perfectly fine now Quote Link to comment https://forums.phpfreaks.com/topic/316164-php-code-help/#findComment-1607575 Share on other sites More sharing options...
Strider64 Posted April 22, 2023 Share Posted April 22, 2023 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. Quote Link to comment https://forums.phpfreaks.com/topic/316164-php-code-help/#findComment-1607577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.