Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. How paranoid should I be? I've never actually dealt with a hacker threat. Is there a Best Practices for recovery?
  3. How paranoid are you - how often do you intend checking the schema? What if the table disappears just after your latest check?
  4. 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.
  5. If a query attempts to access a table that no longer exists mysql> select * from my_test; Empty set (0.01 sec) mysql> drop table my_test; Query OK, 0 rows affected (0.18 sec) mysql> select * from my_test; ERROR 1146 (42S02): Table 'test.my_test' doesn't exist
  6. Today
  7. Yes. PHP code in an .html file will not be processed. However, a .php file does not need to contain any PHP code; it can just contain HTML and will function as an .html file.
  8. Suppose a file contains a form with action="" The HTML form self evaluates with PHP that is in the same file. Perhaps the HTML includes PHP tags for error messages to be displayed (which I've seen in HTML files). Does it matter whether the file itself is stored as a PHP file versus an HTML file?
  9. 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?
  10. What is the most efficient way to determine whether a table exists? I've seen statements that using CREATE TABLE IF NOT EXIST is an indication that one is not properly maintaining a database. But it seems to me that part of a proper maintenance plan would include an immediate response if a table that should be in the db was to suddenly vanish. How can I code to alert (and repair) for a possible hack/compromising of data. I've seen information that explains to SELECT record 1 with the understanding that if there are records, then the table MUST exist. But to the contrary, just because there are NO RECORDS would not indicate that the table is non-existent, only that there are no records. Am I being too nitt-picky?
  11. 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. 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. The session start errors you are seeing suggest you may have PHP configured with session.auto_start=1, either disable the automatic session start or remove your session_start calls. 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.
  12. 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 😂
  13. you should only have one sessionstart in a script. Only put it in the starting script that gets called to get you running. None other. Make the very first line (after the php tag)
  14. 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 😂
  15. 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.
  16. Wrote it so long ago did not remember how it actually worked. PS didn't realize it was you, either.
  17. I read the version of that post before you edited it.
  18. I told you earlier that I looked at it and saw that. Didn't you read that post?
  19. @ginerjm So what's this BS about your not using a class to connect with PDO? Have you read your own code?
  20. And I have no errors when I run what I have just given you. Here is the combined code: function pdoConnect($dbname=null) { $username = '****'; $password = '****'; if ($dbname == null) $host="mysql:host=localhost;charset=utf8"; else $host="mysql:host=localhost;dbname=$dbname;charset=utf8"; try { $db = new PDO($host, $username, $password); } catch (PDOException $e) { echo "Fatal Error<br>Failed to connect to mysql via PDO. PDO Error msg is:<br>".$e->getMessage(); return false; } $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; } //************************************ $mydbname = '****'; if(!$pdo = pdoConnect($mydbname)) { echo "Could not make db connection to database: $mydbname"; exit(); } $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $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> <?php exit(); //**** // *********************************** // ************************************ //**** function DisplayPage() { global $errmsg; $code=<<<heredocs <!DOCTYPE html> <html lang='en'> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> </head> <body> heredocs; echo $code; //********************** $myrow['cats'] = "D\"Reilly"; echo "<div style='margin:2%;border:2px solid black;padding:5px;width:30%;'>".PHP_EOL; echo "<span style='color:red;'>$errmsg</span>".PHP_EOL; echo "<br><br>".PHP_EOL; echo "<form method='POST'>".PHP_EOL; echo "<label>Choose from the below list:</label>".PHP_EOL; echo "<br>&nbsp;&nbsp;&nbsp;".PHP_EOL; echo "<select size='2' style='width:130px;' name='dropdown'>".PHP_EOL; echo "<option value='0'>Pick one</option>".PHP_EOL; echo "<option value=\"{$myrow['cats']}\">{$myrow['cats']}</option>".PHP_EOL; echo "</select>".PHP_EOL; echo "<br><br>".PHP_EOL; echo "<input type='submit' name='btn' value='Show Selection'>".PHP_EOL; echo "</form>".PHP_EOL; echo "</div>".PHP_EOL; exit(); } Hopefully you are all set and we are done.
  21. NO ERROR when entering the file directly in the browser.
  22. Since you haven't posted anything here is something that works for me: //include $ROOT.'db_inc.php'; //************************************ // TRY THIS FUNCTION FOR DB_INC.PHP function pdoConnect($dbname=null) { $username = '****'; $password = '****'; if ($dbname == null) $host="mysql:host=localhost;charset=utf8"; else $host="mysql:host=localhost;dbname=$dbname;charset=utf8"; try { $db = new PDO($host, $username, $password); } catch (PDOException $e) { echo "Fatal Error<br>Failed to connect to mysql via PDO. PDO Error msg is:<br>".$e->getMessage(); return false; } $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; } //************************************ Not used to using constants so wasn't sure if you had a problem there or not. No need for them anyway. Just set the vars inside the function and leave them alone. Ran this code against my own db and it worked fine. And this code added to the code I sent before it also worked just fine.
  23. 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
  24. The line with your error (line 77) is at line 66 in that video. I also notice it isn't accumulating the totals anymore, so I'd still need to see your code from line 1 to line 77 plus the <script> section. This is how it works for me - view sample
  25. Show me your working dbinc.php code And why are you including the css file from the W3 schools website? I think you have been misled. Get rid of it?
  1. Load more activity
×
×
  • 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.