Jump to content

LeonLatex

Members
  • Posts

    396
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by LeonLatex

  1. I mean opening your include files in your browser directly. Accessing them directly to see if there are any errors is at best pointless and at worst misleading. It's pointless because any errors that exist would be shown by PHP when it tries to parse the file during the include process. It can be misleading because the file might depend on variables/functions defined in the main file which are not available when accessed directly and cause errors that otherwise wouldn't exist. I am aware of that. That's why I'm flipping backward. It may seem cumbersome to you Kicken, but it's not to me. It is also a way for me to learn the script and how it is connected. If you use require_once, then PHP will essentially ignore any attempts to require the same file after the first attempt. This can allow you to simply require the file and not worry about if it was already required elsewhere or not. Ideally you would re-structure the code so that the file is only required a single time, but using require_once would be a quick solution while you work towards something better later. I removed all included in the site and removed the session_start(); from header.php. Then it was a short way to make all work. Now there are some "modules" not working, but I am not going to use them in my next project. That is for a friend who asked me if I could make him a music management system for his vinyl collection. He got about 5000- 6000 LP and singles. Thanks for your help Kicken
  2. You should be using require here, not include. The script cannot continue if the file fails to be included so you should just let it fail on the error of not finding the include file rather than a later undefined function error that can get you confused as to what the real problem might be. Thanks kicken. I will try your tip . Opening your include (like db_inc.php) files directly usually isn't going to give you any helpful information, and might just send you down a wrong path. If there's an error with the file it will show up when you include it into the main script you want to run. Do you mean by cut and paste it all into one file? The re-defined function error suggests you are either including your db_inc.php twice. Looks like in marina.php you include header.php and header.php includes db_inc.php. Later on in marina.php you again include db_inc.php which results in the error. You could change your code to use require_once to avoid this problem, or re-structure it so you only include the file once. Ok. So I will change it to "require_once". Where all this calling on all the connections is from I don't understand...or I mean I don't remember. Do you know if they just can be there or stay as they are if I use the "require_once"? I guess I got more of them in other files too since I got some other files with the same error. I dont know where you guys are from except Barand and Gizmola. I am from Norway, so i understand bedtime tierd etc is not the same as in Norway/Europe. But I hope you stay with me (not only me, but stay here at PHP Freaks) as long as possible whereever you are in the world. I am screaming (almost) for help. And I am grateful to everyone who gives me a push.
  3. Yes. I got a session start in both the header.php file and in the login file I can see. And after i put in your code in the db_inc.php (hope I said it right now) i get an error in the login php file when i click the log in button and i have the correct username and password. Do you want the error message from "login.php" ginerjm?
  4. I dont think so because as i wrote to Barand now: That' how it is when it's to much fort and back to many times and things are going to fast. Many funny episodes because of that in my memory 😂
  5. That' how it is when it's to much fort and back to many times and things are going to fast. I got the same problem 😂
  6. Not exactly. Because i got this ERROR left. How to stop the one session and where, I tried to find out, but nope. Could not find it.
  7. NO ERROR when entering the file directly in the browser.
  8. I am now opening each file as a single file with "error_reporting(E_ALL); ini_set('display_errors', '1');" in the top of each file. db_inc.php No ERROR. login.php No ERROR when entering the file, but when i try to login with password and username i get this ERROR (image 1 and 2): header.php Se image 3
  9. Eaten and full... 🙂 I tried to check if the class was following over to another site. So i used the login form to log in, but i get the same error there. OR i can log in, so the connection must be working, but.. There was something. Then i tried to use the registration form to see if it was held open, but error there as well. Is not what has been created as a class something you save on and save for reuse later. Then the class in this connection is probably a DB connection. In this regard, to keep the DB connection open, or am I completely wrong? This is what I have read and Barand is probably the one who made me read about this if I remember correctly, but it must be 1.5 years ago (if i dont remember totaly wrong, but it was among that time we talked together, and you made me the marina script. I guess you have allready deen that this is a part of that system. Unfornatley i have destroyed that script totaly. I am trying to fix so i can reuse parts of it to another project. So i want to use re. I think it's better to use this from you ginerjm: error_reporting(E_ALL); ini_set('display_errors', '1'); I will post the screen dumps.
  10. You misunderstand me a little. I am doing that. I am concentrating on the PDO error in the db_inc.php file. I haven't eaten in 18 - 20 hours because I had to deliver two the design mission, but after that, I will paste the correct ones. Or... I can wait to eat 🙂 This is the db_inc.php file: define("HOST",'*****'); define("USERNAME",'*****'); define("PASSWORD",'*****'); define("DATABASE", '*****'); function pdoConnect($dbname=DATABASE) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } This is the login.php file: <?php session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; include $ROOT.'db_inc.php'; $pdo = pdoConnect(); $loggedin = $_SESSION['member_id'] ?? 0; unset( $_SESSION['member_id'], $_SESSION['isadmin']); if ($loggedin) { header("Location: {$HOST}marina.php"); exit; } $msg = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { $res = $pdo->prepare("SELECT password , member_id , admin FROM member WHERE email = ? "); $res->execute([ $_POST['email'] ]); $row = $res->fetch(); if ($row && password_verify($_POST['password'], $row['password'])) { $_SESSION['member_id'] = $row['member_id']; if ($row['admin'] == 1) { $_SESSION['isadmin'] = 1; } header("Location: {$HOST}index.php"); exit; } else $msg = "<div class='w3-panel w3-red w3-padding'><p>Ugyldig innlogging</p></div>"; } ?> <!DOCTYPE html> <html lang='no'> <head> <title>Brandbu SmåbåtForening båtplasser</title> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css"> <link href='css/footer.css' rel='stylesheet' type="text/css"> </head> <body> <div class='w3-content w3-card-4 w3-light-gray' style='margin-top: 100px;'> <div class='w3-panel w3-black w3-padding'> Marina Management System - Logg Inn </div> <?=$msg?> <form method='POST' class='w3-padding'> <label>E-mail</label> <input type='text' class='w3-input w3-border' name='email'> <label>Password</label> <input type='password' class='w3-input w3-border' name='password'> <br> <button type='submit' class='w3-button w3-blue w3-right'>Logg Inn</button> <br><br><br> </form> </div> </body> </html> This is the header.php file: <?php $disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; $disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled'; $log_btn = isset($_SESSION['member_id']) ? 'Logg ut' : 'Logg inn'; ?> <?php session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; include $ROOT.'db_inc.php'; $pdo = pdoConnect(); $loggedin = $_SESSION['member_id'] ?? 0; unset( $_SESSION['member_id'], $_SESSION['isadmin']); if ($loggedin) { header("Location: {$HOST}index.php"); exit; } $msg = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { $res = $pdo->prepare("SELECT password , member_id , admin FROM member WHERE email = ? "); $res->execute([ $_POST['email'] ]); $row = $res->fetch(); if ($row && password_verify($_POST['password'], $row['password'])) { $_SESSION['member_id'] = $row['member_id']; if ($row['admin'] == 1) { $_SESSION['isadmin'] = 1; } header("Location: {$HOST}members.php"); exit; } else $msg = "<div class='w3-panel w3-red w3-padding'><p>Error: Kunne ikke logge inn!</p></div>"; } ?> <!DOCTYPE html> <html lang='no'> <head> <title>Nikolivia Marina Management System&trade;</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv='Content-Type' content='text/html; charset=utf-8'> <link rel='stylesheet' href='https://www.w3schools.com/w3css/4/w3.css'> <link rel='stylesheet' href='css/main.css'> <link rel='stylesheet' href='css/footer.css'> <style> /* Create four equal columns that floats next to each other */ .column { float: left; width: 25%; padding: 10px; } /* Clear floats after the columns */ .row:after { content: ""; display: table; clear: both; } /* Responsive layout - makes a two column-layout instead of four columns */ @media screen and (max-width: 900px) { .column { width: 50%; } } /* Responsive layout - makes the two columns stack on top of each other instead of next to each other */ @media screen and (max-width: 600px) { .column { width: 100%; } } </style> </head> <body> <header class='w3-container'> <div class="w3-center" style="font-size: 15pt;"><!--<?=PAGETITLE?>--></form></div> <div class="w3-left" style="display: inline-block; padding-top: 16px; font-size: 18pt;"></div> <div style="display: inline-block; padding-top: 16px; font-size: 14pt; margin-right: 10px;" class="w3-right"></div> <div> <div> </div></div></div></div> </header> <div class="w3-bar w3-blue-gray w3-margin-bottom w3-padding"> <a id="nav-home" href="<?=$HOST?>index.php"class="w3-bar-item w3-button">Ta meg hjem</a> <a id="nav-register"href="<?=$HOST?>register.php" class="w3-bar-item w3-button">Registrering</a> <a id="nav-marina" href="<?=$HOST?>marina.php" class="w3-bar-item w3-button">Båtplass</a> <a id="nav-members" href="<?=$HOST?>members.php" class="w3-bar-item w3-button <?=$disabl1?>">Medlemmer</a> <a id="nav-panel" href="<?=$HOST?>invoice/invoice.php" class="w3-bar-item w3-button <?=$disabl2?>">Faktura</a </div> <a id="nav-login" href="<?=$HOST?>login.php" class="w3-bar-item w3-button w3-right"><?=$log_btn?></a> </div>
  11. No, it does not. I try to find the errors myself as well. I care about three files now. If I find the errors in the three files then I have solved the problem in all the others as well. I will make sure to get pasted the correct versions. I have ADHD so I can not promise that it always happens right after the book, but I will try my best so I do not correct what I have already pasted. (😂 that's so stupid).
  12. It was a little silly to put in the ?> after pasting the code. That was because I thought I missed it. So before checking, I pasted it and posted my posting. Sorry, I don't want to waste your time guys. But sometimes (in desperation) we act stupid before we think. We are just humans... So I am deeply very sorry if you have the feeling that I am wasting your time. It was not my intention 😞 I really appreciate your help , from all of you.
  13. I can agree with that in certain situations, but now I have been so stupid that I relied to much on my self, on ther self-proclaimed specialists here at PHP freaks say VSC was recommended to use. I have used it before, but that is wery long time and many years ago. I know it can be silly to rely too much on it since there are a lot of strange things to do, but when you are desperate to find the mistakes it is easy to fall into the same trap that I can also warn against, and that is to rely too much on what is said in a forum. THEN YOU ARE AGAIN WITH AS MANY DIFFERENT ANSWERS AS THERE ARE PERSONS WITH AN INTERNET SUBSCRIPTION. But one eventually learns to trust the right ones. You quickly find out who are the best. I do not need to mention names, but you are one of those I feel is in that category along with someone else in here.
  14. You are both so right. It was not this one. It turned out that this was one I had put on when I pasted it here on PHP Freaks. I just have to scroll back file by file and line by line to find the error. Because the error is deeper in the system than the "db_inc.php" file itself. I guess... no, I am sure I will come back with idiotic questions that are self-explanatory, but this is how it is when you do not have enough sense in your head to give up troubleshooting when you have looked blindly at error after error, are tired and tired, and do not really understand anyone thing. it's good to have men like you here at PHP Freaks.
  15. I get the same error on more of the files in the system. It says: Undefined function 'pdoConnect'. I have to start flipping backward to find the error. Because it must be connected to pdoConnect? The error message tell me so what ever file i try to open. It is so strange that it (pdoConnection) is retrieved from a separate file by the name "db_inc.php". That's the one I posted for you. No, I have to start scrolling back and forth by file to find the error.
  16. Thanks, mac_gyver. My head feels like a stone now. I have only slept 3 hours in 36-37 hours. I will look through the script for the error. I need to fix it myself so I can learn it. If I can't find it I will come back. But, till then I will try to fix it my self. I just need a kick in the right direction, thanks. (The reason why i was so sure the error was in the PDO part is because MS VSC told me so.)
  17. Why do I get this error message? This is the error message i get: ERRORUndefined function 'pdoConnect'. include $ROOT.'db_inc.php'; <?php $pdo = pdoConnect(); define("HOST",'*****'); // Database host. define("USERNAME",'*****'); // Database username . define("PASSWORD",'*****'); // Database password. define("DATABASE", '*****'); // Database name. function pdoConnect($dbname=DATABASE) { ?> $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; }
  18. No, I am not. I will read about it on PHP net. Thanks for the link 🙂
  19. I see. But I am an old man 😛 But at least I am using variables like $title But requinix, can you please tell me about this: <?= $body ?> Why have you replaced php with = after <? and then calling the body variable ?
  20. I am about to set up a test site. When it comes to the HTML tags, where do you split each HTML file by it's tag's that you want to include in the index.php I know there is no standard about this, so it's up to each other how to do it. Like i am split it up in 3 files; header.php , main.php and footer.php. main is used for the sites content. In header.php i got: <!doctype html> <html lang='no' translate="yes"> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> In main.php with the content i got: <body> <?php .................content................ ?> etc And in footer.php i got: </body> </html> With this setup, I have never experienced any problems, but since you have a better understanding and are more experienced than me can tell me another way you are doing it, and why you do it that/your way?
  21. I am not so familiar with this attribute. Is this the reason the translate this site icon shows up beside the address bar? When it's included in an element like a div it will only translate only what's inside the actual div? When it's included in the <HTML> tag will it translate the whole site? (<html lang="no" translate="yes">)
  22. Does anyone know about a good debugger for JS/AJAX and SQL in Visual Studio Code that is worth suggesting? I don't know what to look for.
  23. I had to read your answer over and over again in Google Translate. This was the answer: phpdbg.exe
  24. Ok, you got my respect for that. When I think about it, I think you're right. And now I even don't dare to say more, not even ask another question ( 😉 ). I feel really stupid. I saw the solution. But (as we say in Norway in Norwegian of course) I just had to shit on my own leg. I feel so embarrassed. Before I was never afraid to try new things or find solutions. It must be my age. I am getting older and the Alzheimer's is closing up on me. Requinix, SORRY FOR ASKING STUPID SELF EXPLAINED QUESTIONS. But, thank you for listening
×
×
  • 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.