Jump to content

ginerjm

Members
  • Posts

    5,986
  • Joined

  • Last visited

  • Days Won

    86

Everything posted by ginerjm

  1. Personally I would like to notice the improved knowledge and tougher questions that would tell us that you have learned from your experience with this forum. Just to be see that would be great! Of course that means you will be continuing to work with us when you need to and eventually come to be able to actually provide assistance to those 'noobs' that are soon to follow. HTH
  2. 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)
  3. Wrote it so long ago did not remember how it actually worked. PS didn't realize it was you, either.
  4. I told you earlier that I looked at it and saw that. Didn't you read that post?
  5. 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.
  6. 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.
  7. 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?
  8. This is some of your code which seems to work for me except I did not do a DB connection. session_start(); $ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/'; $HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/'; // COMMENTED OUT FOR THIS TEST //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> <?php exit(); So we can eliminate this code from any error solving?
  9. Are you saying that you pdo connection is WORKING or it is NOT working? Please be sure. Show us JUST the code that you are running for your last post. Nothing else. I don't want stuff that doesn't matter. And we really don't need all the html if it can be avoided. AND the error message and point us to the line that gives that message
  10. Actually I just had a look at my code and I do use an OO connection. But no more OO when I use it. I am a procedural guyy. Ok so does your dbinc.php code work in other scripts without errors? If so we can ignore it in this topice
  11. Does your PDO class work properly? Why do you have a class for creating a db connection? You are not using any classes when you do a prepare or an execute or fetch so why the class just to make the connection?
  12. Why not focus on one error at a time and one script and show us both and see what we can do for you.
  13. So is it working now? And if not, be sure to post the code for us to work with.
  14. Nine hours (and counting) and the OP hasn't been able to remove one (hopefully) errant php tag?
  15. Is this domain storgeweddings.com\ actually YOUR domain? Is your script running on this SAME domain name? And - is it spelled correctly???
  16. Actually, if you are working for people who are administering all of this, you should be able to get the proper setup for sending email from them and not have to rebuild the wheel all by yourself. And if you have to ask us how to execute one single line of php code, perhaps you are in the wrong job.
  17. If you have a company setting then there is probably already an account for this setup. Can't be the first time a web app has had to send mail for your company. Try adding this line to your script or just execute in its own script. MIght solve your riddle echo "sendmail_from is ".ini_get('sendmail_from')."<br>";
  18. You have a domain, correct? You have your own email accounts, no? Setup an account to be used for just this purpose and put that into your email's header.
  19. I believe your problem is the From address. PHP mail function must have a from address that is on your server and it looks like you are using the client's email address as if that user was sending you an email when in fact your web app on your domain is doing the sending.
  20. What MaxDD said is you should buy a book in your language in some computer language. Learn from that and then come back here and compare what you have learned and see how much more sense it will make.
  21. The error was mine. Missing semi before an if line.
  22. Look at the error message and follow what it tells you!
  23. Your code says if 'series' is NOT blank don't show a link. Then your code says if newdate is not blank show a link. I have no idea what your reference to 'high' is in this conversation for. And frankly I really don't know what you are trying to tell us. Take a look at this code and play with the values to see what happens. See how I kept it in php mode to make it easier to code? $game['series'] = ''; $newDate = ''; echo " <div class='details_title text-shadow box-shadow'>Series</div>" if($game['series'] == "") echo "<div class='details_answer text-shadow box-shadow'> <a class='knil' href='series.php?id={$game['series']}'></a></div>"; echo '<div class="details_title text-shadow box-shadow">Completed Date</div>'; if($newDate !== "") echo "<div class='details_answer text-shadow box-shadow'> <a class='knil' href='complete.php'>$newDate</a></div>"; See how I re-arranged your interior div tags?
  24. Your code with some comments (not nearly enough of them though): $username1=$_POST["text"] //error X 2 $age=$_POST["number"] //error x 2 $username="root"; $host="localhost"; $password=" "; $databasename="kemudb"; $conn=mysqli_connect($host, $username, $password, $databsename); //error $sql_read="SELECT * FROM infokemu"; $result=mysqli_query($conn & $sql_read); //error ?> <form method="POST" action=""> USERNAME: <br> <input type="text" name="username1"/> <br> AGE <br> <input type="number" name="age"/> <br> <input type="submit" value="submit"/> </form> Your code will never run even once you clean up all of the errors I have marked. Where did you copy this from? Or did you write it using your apparently very limited knowledge of how to code php and html? I won't begin to explain because I'd rather you step back and do some reading and learning. That will give you a better experience than having me simply tell you what to alter. If you wrote this code then hopefully you can re-learn what you tried to learn and improve. If you copied it please never copy anything from that source again. Here's one thing to think about. When you run this script for the first time what do you think will happen? For one thing, there will not be any $_POST values since you haven't sent your html to the client yet. You should always check for the existence of some input before trying to access it. The next thing is - why do you run a query but you never do anything with the results, if any? Did you not give us 'all' of your code? The current structure of your script is kind of broken up. First you assign some values, then you make a connection and then you send out a form and then you end? Makes it hard to get people to help you when you don't paint a very pretty picture.
  25. Do you have to write a function simply to call another function? And does that global var you are using really exist cause the message is implying that it doesn't?
×
×
  • 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.