-
Posts
403 -
Joined
-
Last visited
-
Days Won
1
Everything posted by LeonLatex
-
OMG, What a h... Now i feel really embarrassed. I removed it and forget to put it back after check whats happening without it.🤪
-
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
Yes, when i run the script stand alone it is ok, but i get a lot of errors when the rest of the script is connected together. It is like you warned me about. So sorry to hear you won't keep up with me. That is an honest choice. Hope to see you around any way from time to time in my weird PHP world. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
Yes, when i run the script stand alone it is ok, but i get a lot of errors when the rest of the script is connected together i get the errors. It is like you warned me about. So sorry to hear you won't keep up with me. That is an honest choice. Hope to see you around any way from time to time in my weird PHP world. -
After destroying a lot of the script that Barand set up for me, I have concluded that developing a lot of what cannot be fixed is the simplest thing than patching together what he developed for me. I should be able to save the rest. Ie. database, calculations, etc. It is the creation/acquisition of variables, connections, sessions, classes, etc. which needs to be set up again. It will be a bit of work, but I think I fix most things on my own now. I will certainly come back to you for tips and advice. I need at least parts of it to put together a music collection management. At least I feel that I have come so far, and then so far that I manage more or more alone and without help from the books, but their professional assessments and tips will always come in handy. That is why I create this thread get to have a fixed thread and relate to it when it comes to this project I am now starting on. I have created a DB connections script. Can I get an assessment of this? I try to run it as a stand-alone script gets to test it and get only 500 errors. What is the reason for that? <?php { $pdo = new PDO('mysql:host=sql31.mcb.webhuset.no; dbname=*****; charset=utf8' , '**********' , '**********'); $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //Gjør noe nyttig //Setter variablene $title and $output } CATCH (PDOException $e) { $output = 'Unable to connect to the database server: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } include_DIR_ . ''; ?>
-
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
IIt's certainly not over yet. It turns out that when I log in, that's not what happens. Because I removed all error check and set everything to requierd_once. Therefore, it seemed to me yesterday that the site logged in. Because it now runs on whether it is wrong or not due to null error check and requierd_once. So now that I have finally slept a few hours and am a little more awake than yesterday, it is back to troubleshooting today as well. It was probably solved a lot yesterday because of your help here at PHP Freaks, but I think I may need you today as well. For it is you who point me in the right direction. I'm not to good enough yet to read the error messages. I hope you can be with me this evening as well if I need you. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
Dont be afraid of that. We have many years ahead of us. I try hard and get back to where I was 12-15 years ago, both in business and knowledge. There have been many tragedies along the way. It started with a business fall from 1000 meters and lots of lost money, many deaths in close family and relationships, one broken marriage, close personal bankruptcy, and ended up drinking two liters of vodka or whiskey straight up a day for 4-5 years, one brain stroke, one daughter (now 25) nearly left me (too), one grandchild 2 years old in October (she's the reason i was waking up ++ etc, etc. + I was exposed to a traffic accident 34 years ago that broke my body in small pieces and which was close to taking my life + ADHD that can not be medicated. Of course, it has given me a lot of life experience. This has among other things taught me to listen to others and share what I have. is knowledge, money, etc. One should never give up. Life is fragile and life is what one makes it. We must live and fulfill our dreams while we can. One day it is too late. So now my goal is to come back to where I was in knowledge and business. It's not easy as 50 years and with so many scars r, a lot of new on the front we work, but there I go. When it comes to business Barand knows a little about what a ride I had in the last half of the 90s and early 2000s. As time goes on, you will notice that Leon can also help, not just ask questions. I appreciate all of you and what you do for me. Thanks! I want to continue and be here. For me, this is the beginning of something long. 1.5 years have already passed. Take care guys 😊 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
I want to say a BIG THANK YOU to all of you who helped me with this problem. It meant a lot to me. I solved it myself in the end, but I would never have been able to do it without their help to kick me in the right direction, so I got on the right track. Thank you very much 😊👍 I would like to give you a donation. It's just a problem. Most of you do not have a PayPal account. How can I show my gratitude to you? 🤓🤔 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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? -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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 😂 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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 😂 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
NO ERROR! -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
NO ERROR when entering the file directly in the browser. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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 -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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™</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> -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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). -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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. -
PDO error - Undefined function 'pdoConnect'.
LeonLatex replied to LeonLatex's topic in PHP Coding Help
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.) -
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; }