Jump to content

rocky48

Members
  • Posts

    261
  • Joined

  • Last visited

Everything posted by rocky48

  1. Looking through examples on the web I realised that the array statement syntax was wrong it should be in the format: $fname=>$_POST['fname']. It still does not populate the DB, but there are no error messages? Run out of ideas! Here's the code so far (I have not posted the html part, these are the first 44 lines): <?php // initialization session_start(); error_reporting(E_ALL & ~ E_NOTICE); ini_set('display_errors','1'); // why not have the connection code actually make the connection too, so that you don't need another line of code? require "conn/connect_seniorform.php"; // note: this code uses the much simpler and more modern PDO database extension // when you make the connection - // set the character set to match your database tables, so that no character conversion occurs over the connection // set the error mode to use exceptions, so that all the database statements will use exceptions (this is the default now in php8, but set it anyways) // set emulated prepared queries to false, you want to run real prepared queries // set the default fetch mode to assoc, so that you don't need to specify it in each fetch statement $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // post method form processing $status=""; $POST=""; if($_SERVER["REQUEST_METHOD"]=="POST") { array($fname=>$_POST['fname'],$lname=>$_POST['lname'],$email=>$_POST['email']); if(empty($fname)|| empty($lname)|| $email){ $status="All fields are compulsory."; }elseif(strlen($fname)>= 255 || !preg_match("/^[a-zA-Z-'\s+$/", $fname)){ $status="Please enter a valid name"; }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $status="Please Enter a valid email"; }else{ $sql="INSERT INTO senior_dat(fname,lname,email) VALUES (:fname, :lname, :email)"; $stmt=$pdo->prepare($sql); $stmt->execute(['fname'=>$fname], ['lname'=>$lname],['email'=>$email]); $status="Your entrys have been accepted"; $fname=""; $lname=""; $email=""; } } // hrml document starts here... ?>
  2. Sorry Barand I faithfully copied your entry on your previous post. I removed the E_NOTICE by adding '& ~ E_NOTICE' which removed any notices, but still no entries in the DB. The entry validation is not working, as I tried not entering any data to see if the message would be displayed, but they didn't! So it looks like the INSERT is not working.
  3. I think were almost there! on lines 22, 23, 24 I get this Notice: Notice: Undefined variable: POST in /homepages/30/d593365489/htdocs/MFC1066/Mac2.php on line 22 Notice: Trying to access array offset on value of type null in /homepages/30/d593365489/htdocs/MFC1066/Mac2.php on line 22 I created a Null $post ($POST=""), but then I got this for each posted variable: Warning: Illegal string offset 'fname' in /homepages/30/d593365489/htdocs/MFC1066/Mac2.php on line 23 Notice: Uninitialized string offset: 0 in /homepages/30/d593365489/htdocs/MFC1066/Mac2.php on line 23 Still nothing written to DB! Searching the web it seems that the POST's should be in an array, but how can you do that when there isn't a common variable? I looked at a simple example on the web where fruit was the variable and the array was apples, pears and oranges. Tried this: array ( $fname=$POST['fname']; $lname=$POST['lname']; $email=$POST['email']; ) But this gave the same warning! Not sure where to go from here!
  4. Komodo does highlight braces! I believe that the problem is in the code between lines 21 to 43. The first opening curly brace (Ln22)does not have a closing curly brace! The curly brace on line 28 highlights the closing curly brace on line 43. That seems wrong to me! Should it be an elseif? Also on line 31 the closing brace is on line 42, which to me seems wrong. With so many else statements I am very confused as to where the braces should go! The line numbers are based on the copy of the file I last posted. Could you help me get the braces in the right place?
  5. I am 74 years old and now struggle with programming and not that experienced. I did a lot of programming over 10 years ago, but my memory is not so good. I use Komodo Edit which does help to format as i type. Please don't use abbreviations, I worked out what s/b was, but what does IMO and OP stand for? You may say why am I trying to struggle with programming, but it keeps my brain cells working! Don't forget you may be in the same position one day!
  6. Managed to figure that out, but have another problem! Parse error: syntax error, unexpected end of file in C:\wamp64\www Im know that this can be un-equal curly brackets, but they look OK. On the web it said that it can be an unclosed php code. Looking at the code, you have <? but within quotes? Is the error check mistaking them for php code terminator? Here is the file: <?php // initialization session_start(); error_reporting(E_ALL); ini_set('display_errors','1'); // why not have the connection code actually make the connection too, so that you don't need another line of code? require "conn/connect_seniorform.php"; // note: this code uses the much simpler and more modern PDO database extension // when you make the connection - // set the character set to match your database tables, so that no character conversion occurs over the connection // set the error mode to use exceptions, so that all the database statements will use exceptions (this is the default now in php8, but set it anyways) // set emulated prepared queries to false, you want to run real prepared queries // set the default fetch mode to assoc, so that you don't need to specify it in each fetch statement $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // post method form processing $status=""; if($_SERVER["REQUEST_METHOD"]=="POST"){ $fname=$POST['fname']; $lname=$POST['lname']; $email=$POST['email']; if(empty($fname)|| empty($lname)|| $email){ $status="All fields are compulsory."; }else{ if(strlen($fname)>= 255 || !preg_match("/^[a-zA-Z-'\s+$/", $fname)){ $status="Please enter a valid name"; }else{ if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ $status="Please Enter a valid email"; }else{ $sql="INSERT INTO senior_dat(fname,lname) VALUES (:fname, :lname)"; $stmt=$pdo->prepare($sql); $stmt->execute(['fname'=>$fname], ['lname'=>$lname]); $status="Your entrys have been accepted"; $fname=""; $email=""; } } } // hrml document starts here... ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="RSD 5.0.3519"> <title>Senior Form</title> <link rel="stylesheet" href="css/bootstrap4.min.css"> <link rel="stylesheet" href="css/wireframe-theme.min.css"> <script>document.createElement( "picture" );</script> <script class="picturefill" async="async" src="js/picturefill.min.js"></script> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Averia+Sans+Libre:400,b%7CRoboto:400,900,b"> </head> <body class="body-3"><div class="responsive-picture picture-1 align-content-md-center"> <picture> <img alt="Placeholder Picture" width="1200" height="300" src="./images/1066MFC%20Banner.jpg" loading="lazy"> </picture> </div> <nav class="container-grid navbar navbar-expand-lg navbar-dark bg-dark"> <h3 class="navbar-brand">MENU</h3><button type="button" class="btn navbar-toggler navbar-toggler-icon button Dropdown-toggle" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-label="Toggle navigation"></button> <div class="container-grid collapse navbar-collapse" id="navbarNavDropdown"> <ul class="list-container navbar-nav"> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="index.html" title="">HOME</a> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="about.html" title="">ABOUT</a> </li> <li class="list-item-container nav-item dropdown"> <a class="link-text nav-link dropdown-toggle" href="members.html#navbarNavDropdown" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">MEMBERS</a> <div class="container-grid dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <a class="link-text dropdown-item" href="members.html" title="">Members</a> <a class="link-text dropdown-item" href="aerodrome.html" title="PEBSHAM AERODROME">Pebsham Aerodrome</a> <a class="link-text dropdown-item" href="emergency%20numbers.html">Emergency Numbers</a> </div> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="newmem.html" title="New-Member">NEW MEMBER</a> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="contact.html" title="">CONTACT</a> </li> </ul> <a class="link-text text-link-4" href="https://1066modelflying.club/coppermine/index.php" title="Gallery">GALLERY</a> </div> </nav> <?php // display and clear any success message if(!empty($_SESSION['success_message'])) { echo "<p>{$_SESSION['success_message']}</p>"; unset($_SESSION['success_message']); } ?> <h1>SENIOR RENEWAL FORM</h1> <?php // display any errors if(!empty($errors)) { echo '<p>'; echo implode('<br>',$errors); echo '</p>'; } ?> <form method="post"> <label><b>First Name:</b><br><input type="text" name="first_name" size="20" maxlength="40" value="<?=htmlentities($post['fname']??'',ENT_QUOTES)?>"></label> <br> <label><b>Last Name:</b><br><input type="text" name="first_name" size="20" maxlength="40" value="<?=htmlentities($post['lname']??'',ENT_QUOTES)?>"></label> <br> <label><b>email:</b><br><input type="text" name="first_name" size="20" maxlength="40" value="<?=htmlentities($post['email']??'',ENT_QUOTES)?>"></label> <br> <input type="submit" value="submit"> </form> </body> </html>
  7. Hi Mac Tried your line with square brackets around the execute: $stmt->execute[ $post['fname'], $post['lname']] but still gives an error: Parse error: syntax error, unexpected ',', expecting ']' in /homepages/30/d593365489/htdocs/MFC1066/Mac1.php on line 48 But surely it's got to have a comma and and an opening square bracket? Here's the complete file: <?php // initialization session_start(); // why not have the connection code actually make the connection too, so that you don't need another line of code? require "conn/connect_seniorform.php"; // note: this code uses the much simpler and more modern PDO database extension // when you make the connection - // set the character set to match your database tables, so that no character conversion occurs over the connection // set the error mode to use exceptions, so that all the database statements will use exceptions (this is the default now in php8, but set it anyways) // set emulated prepared queries to false, you want to run real prepared queries // set the default fetch mode to assoc, so that you don't need to specify it in each fetch statement $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // post method form processing if($_SERVER["REQUEST_METHOD"]==="POST") { // inputs: first_name (add others once code is working) // trim all the input data at once $post = array_map('trim',$_POST); // if any input is an array, use a recursive trim call-back function here instead of php's trim // validate all inputs // first name if($post['fname'] === '') { $errors['fname'] = "First Name is required"; } if($post['lname'] === '') { $errors['lname'] = "Last Name is required"; } // validate other inputs here... // if no errors, use the input data if(empty($errors)) { $sql = "INSERT INTO senior_dat (fname), (lname) VALUES (?,?)"; $stmt = $pdo->prepare($sql); // note: the following try/catch error handling deals with having a (single) unique column (email) defined in your database table // if you have multiple unique columns defined, you would execute a SELECT query inside the catch code to find which column(s) contain duplicate values matching the input data and setup an error message for each one try { // a 'local' try/catch to handle a specific error type $stmt->execute[ $post['fname'], $post['lname']] } catch (PDOException $e) { if($e->errorInfo[1] == 1062) // duplicate key error number { $errors['email'] = "Email is already in use"; } else { throw $e; // re-throw the pdoexception if not handled by this logic } } } // if no errors, success if(empty($errors)) { $_SESSION['success_message'] = "Form saved OK"; die(header("Refresh:0")); } } // hrml document starts here... ?> <?php // display and clear any success message if(!empty($_SESSION['success_message'])) { echo "<p>{$_SESSION['success_message']}</p>"; unset($_SESSION['success_message']); } ?> <h1>SENIOR RENEWAL FORM</h1> <?php // display any errors if(!empty($errors)) { echo '<p>'; echo implode('<br>',$errors); echo '</p>'; } ?> <form method="post"> <label><b>First Name:</b><br><input type="text" name="first_name" size="20" maxlength="40" value="<?=htmlentities($post['first_name']??'',ENT_QUOTES)?>"></label> <br> <label><b>Last Name:</b><br><input type="text" name="first_name" size="20" maxlength="40" value="<?=htmlentities($post['first_name']??'',ENT_QUOTES)?>"></label> <br> <input type="submit" value="submit"> </form> Any suggestions?
  8. Hi Mac Trying to use your code, but having problems with posting multiple values! I believe this was a mistake in your code: try { // a 'local' try/catch to handle a specific error type $stmt->execute([ //<<Whats this [ for? $post['fname'], ]); //<<Here! } catch (PDOException $e) { if($e->errorInfo[1] == 1062) // duplicate key error number { $errors['email'] = "Email is already in use"; } else { throw $e; // re-throw the pdoexception if not handled by this logic I altered it to post 2 values: try { // a 'local' try/catch to handle a specific error type $stmt->execute(array($post(['fname'],['lname'])) } catch (PDOException $e) { if($e->errorInfo[1] == 1062) // duplicate key error number { $errors['email'] = "Email is already in use"; } else { throw $e; // re-throw the pdoexception if not handled by this logic } } } But I get an error: I probably got this code wrong as I am not sure of the correct syntax for posting multiple $POST's. Can you show me the correct syntax for this example and how in the future I can add all my form fields into this code.
  9. Hi Mac I am running it on my host server, so don't need URL! I Have been looking at your code an d I have a couple of queries! I have been working on the assumption that the form code had to be on a separate file and it post it to that php file which is stated in the form header? Is this a different way of doing this using PDO? Also, you have a comment saying html document here! Is this where I would put any page header code?
  10. I found on my host a connection script so I tried that and it works and gives my a message to say that it is connected. I put that a the top of my shortened script and entered my name in the name input box. I then checked the database and nothing was written. I have tried to use some prepared statements, but it did not work. As this is new to me I may have got the script wrong. Can you help? <?php $host_name = 'xxxxxx'; $database = 'xxxx'; $user_name = 'xxxx'; $password = 'xxxx'; $link = new mysqli($host_name, $user_name, $password, $database); if ($link->connect_error) { die('<p>Failed to connect to MySQL: '. $link->connect_error .'</p>'); } else { echo '<p>Connection to MySQL server successfully established.</p>'; } // check if a form has been submitted if ($_SERVER["REQUEST_METHOD"]== "POST" { $name = $POST['name']; $sql = $mysqli->prepare("INSERT INTO senior_dat VALUES (?)"); $label = 'PHP'; $sql->bind_param("is",$label); $sql->execute echo "<h3> Form saved OK"</h3>; else echo "nl2br(You have an input error)"; } ?>
  11. Thanks for the information! I'm thinking its the connection code that isn't working! I have used the following format before and haven't had any problems. I've redacted the login data for obvious reasons. I have double checked the loin data and know that it is correct. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //set up a connection function get_db_conn_senior() { $host_name = "xxxxxxxxxxxxxxx"; $database = "xxxxxxxxxx"; // Change your database name $username = "xxxxxxxxxx"; // Your database user id $password = "xxxxxxxxxx"; // Your password //connect to server and select database; you may need it $conn = new mysqli($host_name, $username, $password, $database); echo "Connected"; //if connection fails, stop script execution if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } return $conn; } ?> I have put the echo in to see if it connects, but no message is shown. But surely if it did not connect I would get the fail message? I cut down the html file to one input, but still not populating the database. What can I do next to get this working?
  12. Just thought I'd mention, the routine that works out your age in your profile must be wrong, as my age is 74, no 71?

  13. I have not done any php coding for some time and I can't figure out why this coding is not working? I am trying to create a form for my club so that members can fill in a form online. I have written a form which is in html which using POST collects the data from the form and should INSERT it into the database. Here is the html file: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="RSD 5.0.3519"> <title>Senior Form</title> <link rel="stylesheet" href="css/bootstrap4.min.css"> <link rel="stylesheet" href="css/wireframe-theme.min.css"> <script>document.createElement( "picture" );</script> <script class="picturefill" async="async" src="js/picturefill.min.js"></script> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Averia+Sans+Libre:400,b%7CRoboto:400,900,b"> </head> <body class="body-3"><div class="responsive-picture picture-1 align-content-md-center"> <picture> <img alt="Placeholder Picture" width="1200" height="300" src="./images/1066MFC%20Banner.jpg" loading="lazy"> </picture> </div> <nav class="container-grid navbar navbar-expand-lg navbar-dark bg-dark"> <h3 class="navbar-brand">MENU</h3><button type="button" class="btn navbar-toggler navbar-toggler-icon button Dropdown-toggle" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-label="Toggle navigation"></button> <div class="container-grid collapse navbar-collapse" id="navbarNavDropdown"> <ul class="list-container navbar-nav"> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="index.html" title="">HOME</a> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="about.html" title="">ABOUT</a> </li> <li class="list-item-container nav-item dropdown"> <a class="link-text nav-link dropdown-toggle" href="members.html#navbarNavDropdown" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">MEMBERS</a> <div class="container-grid dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <a class="link-text dropdown-item" href="members.html" title="">Members</a> <a class="link-text dropdown-item" href="aerodrome.html" title="PEBSHAM AERODROME">Pebsham Aerodrome</a> <a class="link-text dropdown-item" href="emergency%20numbers.html">Emergency Numbers</a> </div> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="newmem.html" title="New-Member">NEW MEMBER</a> </li> <li class="list-item-container nav-item"> <a class="link-text nav-link" href="contact.html" title="">CONTACT</a> </li> </ul> <a class="link-text text-link-4" href="https://1066modelflying.club/coppermine/index.php" title="Gallery">GALLERY</a> </div> </nav> <h1>SENIOR RENEWAL FORM</h1> <form name="senior_data" method="post" <fieldset><ledgend>Please enter your infomation in the form below: </legend> <h2>2023 Senior Membership Renewal Form</h2> <p>Please remember that the club & BMFA membership runs out at the end of December. <br> 2023 1066 MFC Membership &#163;10.00<br> BMFA Membership/Insurance &#163;40.00<br> Family Partner Senior &#163;27.00<br> CAA Operator Fee &#163;10.00<br> BMFA Membership Reward Card &#163;4.50<br> British Drone Flyers Association Members &#163;5.00<br> </p><br> <p><b>Name:</b><br> <input type="text" name="name" size="20" maxlength="40"/></p> <label for="dob"><b>Date of birth:</b></label> <input type="date" id="dob" name="dob " value="" min="1900-01-01" max="2050-12-31"> <p><b> <br> <label for="addr">Address:</label><br> <textarea id="addr" name="addr" rows="4" cols="50"> </textarea> <br> <label for="phone">Phone number:</label> <input type="tel" id="phone" name="phone" required> <br> <label for="mob">Mobile number:</label> <input type="tel" id="mob" name="mob" required> <br> <label for="email">Email:</label> <input type="email" id="email" name="email"> <br> <label for="bmfa_no">BMFA No:</label> <input type="text" id="bmfa_no" name="bmfa_no"> <br> <label for="caa_no">CAA Operator No:</label> <input type="text" id="caa_no" name="caa_no"><br> <label for="club_membership">Do you wish that the club obtains your BMFA membership, Insurance & CAA renewal:</label> <select name="club_membership" id="club_membership"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> </select> <br> <label for="Ctry">Are you a Country Member:</label> <select name="Ctry" id="Ctry"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> </select> <br> <label for="caa">If you answered YES to the previous question,. have you a current BMFA and CAA membership:</label> <select name="caa" id="caa"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> <option value="na">N/A</option> </select> <br> <label for="rewd">Do you wish to purchase a BMFA Membership/Reward Card:</label> <select name="rewd" id="rewd"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> </select> <br> <label for="fam">Are you a family member:</label> <select name="fam" id="fam"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> </select> <br> <label for="bdf">Do you wish to join the British Drone flyers Association, instead of the BMFA:</label> <select name="bdf" id="bdf"> <option value="blank "> </option> <option value="NO">NO</option> <option value="YES">YES</option> </select> <p>Please note that if you join the BDF you can also fly fixed wing/ helicopters as well!</p> <br> <label for="pay_opt">Ho do you wish to pay:</label> <select name="pay_opt" id="pay_opt"> <option value="blank "> </option> <option value="chq">CHEQUE</option> <option value="csh">CASH</option> <option value="bacs">BACS</option> </select> <br> <p><b>Payment required: &#163;</b><input type="text" name="pay" size="20" maxlength="40"/></p> <br> <p style="background-color:tomato;">I apply for membership of the 1066 Model Flying Club and agree to abide by the rules. By doing so agree to allow the club to use your details in respect of the GDPR regulations for the processing of your renewal, a copy of which can be found on the club website members page. </p> <br> <label for="date">Date:</label> <input type="text" id="date" name="date" pattern="[0-9]{2}/[0-9]{2}/[0-9]{4}" required> <br> <label for="sign">Sign here:</label> <input type="text" id="sign" name=sign" required> <br> <input type="submit" value="submit"> Here is the file that copies the posted output and inserts it into the database: <?php include ("conn/connect_seniorform.php"); $conn=get_db_conn_senior(); if ($_SERVER["REQUEST_METHOD"]== "POST"{ $id = $REQUEST['id']; $name = $REQUEST['name']; $dob = $REQUEST['dob']; $addr = $REQUEST['addr']; $phone= $REQUEST['phone']; $mob = $REQUEST['mob']; $email =$REQUEST['email']; $bmfa_no = $REQUEST['bmfa_no']; $caa_no = $REQUEST['caa_no']; $rewd = $REQUEST['rewd']; $fam = $REQUEST['fam']; $ctry = $REQUEST['ctry']; $ctry_bmfa = $REQUEST['ctry_bmfa']; $bdf = $REQUEST['bdf']; $pay_opt = $REQUEST['pay_opt']; $pay = $REQUEST['pay']; $date = $REQUEST['date']; $sign = $REQUEST['sign']; $sql = "INSERT INTO senior_dat VALUES ($id,$name,$dob,$addr,$phone,$mob,$email,$bmfa_no,$caa_no,$rewd,$fam,$ctry,$ctry_bmfa,$bdf,$pay_opt,$pay,$date,$sign"); if(mysqli_query($conn,$sql)){ echo "<h3> Form saved OK"</h3>; }else{ echo nl2br(You have an input error); } } mysqli_close($conn); ?> I do not get any errors, but nothing appears in the database. As I have not done any php coding in years I used some methods I found on the web. Can anyone tell me where I am going wrong?
  14. I think it was the parent bit that was stopping it! However there are still problems! Here is the error: Now I have cleared the original problem, It still errors! Now it is finding fault with the font scripts. Here is the error: Fatal error: Uncaught Exception: FPDF error: Incorrect font definition file name: /frscript.php in /homepages/30/d593365489/htdocs/fpdf.php:271 Stack trace: #0 /homepages/30/d593365489/htdocs/fpdf.php(1142): FPDF->Error('Incorrect font ...') #1 /homepages/30/d593365489/htdocs/fpdf.php(459): FPDF->_loadfont('/frscript.php') #2 /homepages/30/d593365489/htdocs/Prnpdf.php(110): FPDF->AddFont('french script m...', '', '/frscript.php') #3 {main} thrown in /homepages/30/d593365489/htdocs/fpdf.php on line 271 What is also wierd even if I change the font it still reports the error with the French Script font? Had a quick look at the font file, but can't see anything wrong. I'm guessing there is a change in the frscript.php, but I am not knowledgable to spot it! Before the upgrade to 7.2 it was working OK.
  15. Tried as suggested but get the same error! Fatal error: Uncaught Error: Call to undefined method FPDF::FPDF() in /homepages/30/d593365489/htdocs/Prnpdf.php:78 Stack trace: #0 /homepages/30/d593365489/htdocs/Prnpdf.php(108): PDF->__construct('L', 'mm', 'A4') #1 {main} thrown in /homepages/30/d593365489/htdocs/Prnpdf.php on line 78 Also tried amending this line: $pdf = new PDF($ort,'mm','A4'); to: $pdf = new __construct($ort,'mm','A4');, but that did not work and gave this error: Fatal error: Uncaught Error: Class '__construct' not found in /homepages/30/d593365489/htdocs/Prnpdf.php:108 Stack trace: #0 {main} thrown in /homepages/30/d593365489/htdocs/Prnpdf.php on line 108. Where do I go rom here? 😂
  16. I have used this program for many years without problems. My ISP urged me to upgrade PHP to 7.2 and it was working OK. Just went to use it and I get an error when parsing my FPDF file. Here is the error: Connected (added this to check if connected) Fatal error: Uncaught Error: Call to undefined method PDF::FPDF() in /homepages/30/d593365489/htdocs/Prnpdf.php:78 Stack trace: #0 /homepages/30/d593365489/htdocs/Prnpdf.php(108): PDF->PDF('L', 'mm', 'A4') #1 {main} thrown in /homepages/30/d593365489/htdocs/Prnpdf.php on line 78 I have not altered the file in any way, so why is this happening? Is it to do with PHP upgrade?😖 Here is the file: <?php include("connect_Verses4Cards.php"); $conn=get_db_conn_verse(); session_start(); $display_block =""; $color=""; $r =""; $g =""; $b =""; $image =""; //Get the Card Variables $Get_Size_sql = "SELECT * FROM `CSize` WHERE `Size` ='".$_POST["CSize"]."'"; $Get_Size_res = mysqli_query($conn, $Get_Size_sql) or die(mysqli_error($conn)); if (mysqli_num_rows($Get_Size_res) < 1) { //this Card does not exist $display_block = "You have selected an invalid Card size. Please try again."; } else { //get the print variables while ($Size_info = mysqli_fetch_array($Get_Size_res)) { $BoxX = stripslashes($Size_info['BoxX']); $Cellw = stripslashes($Size_info['Cellw']); $Cellh = stripslashes($Size_info['Cellh']); $SizeI = stripslashes($Size_info['Size']); $SID = stripslashes($Size_info['SID']); $floatx = stripslashes($Size_info['floatx']); $floaty = stripslashes($Size_info['floaty']); $floatw = stripslashes($Size_info['floatw']); $floath = stripslashes($Size_info['floath']); $ort = stripslashes($Size_info['ort']); } //create the display string $display_block = "$ort"; } //verify the Event exists //$the_id = mysqli_real_escape_string($mysqli, $_SESSION[VID]); $Get_Verse_sql = "SELECT id, Event, Sub_Type, Verse FROM verses WHERE id='".$_SESSION['Test']."'"; $Get_Verse_res = mysqli_query($conn, $Get_Verse_sql) or die(mysqli_error($conn)); if (mysqli_num_rows($Get_Verse_res) < 1) { //this Event does not exist $display_block = "You have selected an invalid Event. Please try again."; } else { //get the Event ID while ($Verse_info = mysqli_fetch_array($Get_Verse_res)) { $Verse = stripslashes($Verse_info['Verse']); } //create the display string $display_block = "$Verse"; //free results mysqli_free_result($Get_Verse_res); mysqli_free_result($Get_Size_res); //close connection to MySQL } mysqli_close($conn); require('fpdf.php'); class PDF extends FPDF { var $B; var $I; var $U; var $HREF; function PDF($orientation='P', $unit='mm', $size='A4') { // Call parent constructor $this->FPDF($orientation,$unit,$size); // Initialization $this->B = 0; $this->I = 0; $this->U = 0; $this->HREF = ''; } function SetStyle($tag, $enable) { // Modify style and select corresponding font $this->$tag += ($enable ? 1 : -1); $style = ''; foreach(array('B', 'I', 'U') as $s) { if($this->$s>0) $style .= $s; } $this->SetFont('',$style); } } $color = $_POST['color']; $r = substr($color,0,3); $g = substr($color,3,3); $b = substr($color,6,3); $image=$_POST['image']; $pdf = new PDF($ort,'mm','A4'); $pdf->AddPage(); $pdf->AddFont('French Script MT','','/frscript.php'); $pdf->AddFont('Batavia','','Batavia_.php'); $pdf->AddFont('Algerian','','Alger.php'); $pdf->AddFont('Bladerunner','','BLADRMF_.php'); $pdf->AddFont('Brush Script','','BRUSHSCI.php'); $pdf->AddFont('Helterskelter','','Helte___.php'); $pdf->AddFont('Justice','','Justice_.php'); $pdf->AddFont('Magneto','','MAGNETOB.php'); $pdf->AddFont('Old English','','OldEngl.php'); $pdf->AddFont('Sneakerhead Outline','','Sneabo__.php'); $pdf->AddFont('Trendy','','Trendy__.php'); $pdf->AddFont('Vladimir Script','','VLADIMIR.php'); $pdf->SetLeftMargin('float0'); $pdf->SetTextColor($r,$g,$b); $pdf->SetFont($_POST['fontface'],'',$_POST['font']); $pdf->SetXY($BoxX, $_POST['Top']); $pdf->Image($image,$floatx,$floaty,$floatw,$floath,'',''); $pdf->MultiCell($Cellw,$Cellh,$display_block,'' ,'C'); //$pdf->SetDisplayMode('fullpage',''); $pdf->SetFont(''); $pdf->Output('verse.pdf','D'); //end: ?>
  17. I am trying to make my site more secure by staring a session at login which uses the user_id to identify a user. I had a previous post which was to change password, which I eventually found was due to not putting ob_start before the session start. Using this method I tried adding the same to another file, so that an intruder can't circumvent the login procedure. When I run this file all I get is a blank screen, no errors are shown. I added to show errors: ini_set('display_errors',1); error_reporting(E_ALL); Here is the script that is not working: <?php # MFC1066 - Club_Info.php // This is the main page for the site. ob_start(); session_start(); ini_set('display_errors',1); error_reporting(E_ALL); // Include the configuration file: require_once ('includes/config.inc.php'); // Set the page title and include the HTML header: $page_title = 'Club Info'; include ('includes/header1.html'); // If no user_id session variable exists, redirect the user: if (!isset($_SESSION[$uid])) { $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. ?> <?php include ('includes/info.html'); ?> <?php // Include the HTML footer file: include ('includes/footer1.html'); ?> Here is the Login script: <?php # - login.php // This is the login page for the site. //ini_set('display_errors',1); //error_reporting(E_ALL); // Start output buffering: ob_start(); session_start(); $uid=$_SESSION('user_id'); require_once ('includes/config.inc.php'); $page_title = 'Login'; include ('includes/header1.html'); if (isset($_POST['submitted'])) { require_once('includes/Connect_login.php'); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } // Validate the BMFA No: if (!empty($_POST['BMFA'])) { $b = mysqli_real_escape_string ($dbc, $_POST['BMFA']); } else { $b = FALSE; echo '<p class="error">You forgot to enter your BMFA number!</p>'; } if ($e && $p && $b) { // If everything's OK. // Query the database: $q = "SELECT user_id, first_name, user_level, BMFA_No FROM users WHERE (email='$e' AND pass=SHA1('$p') AND BMFA_No= ('$b')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); $_SESSION['loggedin']='user_id'; mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'mempage.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login3.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <p><b>BMFA No:</b> <input type="text" name="BMFA" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <h2>Forgot your password? Click on this link:<a href="forgot_password.php"target="_blank">Forgot Password</a></h2> <?php // Include the HTML footer. include ('includes/footer1.html'); ?> I have isolated the problem to the redirect code lines 15 - 19, but can't see why it does not work! Please can you help?
  18. I take it back! The SESSION is still not being recognized! I am at my wits end trying to solve this problem. Please can anyone help?
  19. I eventually found that ob_start should go BEFORE Session_start, so it now recognizes the session. However, I now have another problem! The query is not working on line 436 of change_password.php. All I get is the echo of the array when the line is like so: $q = "UPDATE users SET pass=SHA1('$p') WHERE user_id={$_SESSION=$_POST['user_id']"; I tried changing it but keep getting errors. I tried this: $q = "UPDATE users SET pass=SHA1('$p') WHERE user_id={$_SESSION['loggedin']::'user_id'}"; As this field is not one that has been posted, how do you retrieve it from the record?
  20. Having some more thoughts on this! Do I need the line: $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); Does this capture all of the data in the SELECT query? So if I then have the line: $_SESSION['loggedin']='user_id'; Should this not pass the user_id as a named session, so when I try to use it in the change_password script it will identify the user? Is my thinking correct or am I totally wrong?
  21. Just realized why it returns to home page! Its due to this line: if (!isset($_SESSION['loggedin'])) { $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } So I guess it is not recognizing the session. Should I have the session start on this script?
  22. Firstly, I was at first trying to use the email address as the session data to use throughout the session, but soon realized tat was not a good idea. So my scripts were not totally changed. Here are the changes I have made. Login script: // Register the values & redirect: //$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); $_SESSION['loggedin']=$_POST['user_id']; As you can see I have only commented out the superfluous line for now. Now to the Change_password script: $q = "UPDATE users SET pass=SHA1('$p') WHERE user_id={$_SESSION['loggedin']::$_POST['user_id']}"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); When i run this on my localhost, I get the following error: According to the web query that strange sounding error message is to do with double colons. It is inferring that it should be :: and not =, but when I changed it to the double colons it returned to my home page and did not process the html code on lines 62 onward. The ob_start is in the header1.html script! Any ideas to why this is happening?
  23. I am having difficulty finding out what is wrong with these scripts. When a user logs on a session is started in the logon script: Login.php: <?php # - login.php // This is the login page for the site. session_start(); require_once ('includes/config.inc.php'); $page_title = 'Login'; include ('includes/header1.html'); if (isset($_POST['submitted'])) { require_once('includes/Connect_login.php'); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } // Validate the BMFA No: if (!empty($_POST['BMFA'])) { $b = mysqli_real_escape_string ($dbc, $_POST['BMFA']); } else { $b = FALSE; echo '<p class="error">You forgot to enter your BMFA number!</p>'; } if ($e && $p && $b) { // If everything's OK. // Query the database: $q = "SELECT user_id, first_name, user_level, BMFA_No FROM users WHERE (email='$e' AND pass=SHA1('$p') AND BMFA_No= ('$b')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); $_SESSION['loggedin']=$_POST['user_id']; echo $_POST['user_id']; mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'mempage.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <p><b>BMFA No:</b> <input type="text" name="BMFA" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <h2>Forgot your password? Click on this link:<a href="forgot_password.php"target="_blank">Forgot Password</a></h2> <?php // Include the HTML footer. include ('includes/footer1.html'); ?> I am using output buffering, so that I can include files and only send to the server when the form is submitted. Would this screw up the sessions? I'm not sure if the way I have set the session is correct on line 48 as there is a session which is saving the array of the MYSQL query. I am using a book for this example, so I don't understand how the first session statement is saving the array, if it is not named? The script allows me to login OK and on the page it redirects to I have put a button that allows the user to change their password. This runs the change_password.php script. <?php # Change_password.php // This page allows a logged-in user to change their password. session_start(); ob_start; require_once ('includes/config.inc.php'); $page_title = 'Change Your Password'; include ('includes/header1.html'); // If no first_name session variable exists, redirect the user: if (!isset($_SESSION['email'])) { $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } print_r($_POST); if (isset($_POST['submitted'])) { require_once('includes/Connect_login.php'); // Check for a new password and match against the confirmed password: $p = FALSE; if (preg_match ('/^(\w){4,20}$/', $_POST['password1']) ) { if ($_POST['password1'] == $_POST['password2']) { $p = mysqli_real_escape_string ($dbc, $_POST['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($p) { // If everything's OK. // Make the query. $q = "UPDATE users SET pass=SHA1('$p') WHERE user_id={$_SESSION=$_POST['user_id']"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send an email, if desired. echo '<h3>Your password has been changed.</h3>'; mysqli_close($dbc); // Close the database connection. include ('includes/footer.html'); // Include the HTML footer. exit(); } else { // If it did not run OK. echo '<p class="error">Your password was not changed. Make sure your new password is different than the current password. Contact the system administrator if you think an error occurred.</p>'; } } else { // Failed the validation test. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); // Close the database connection. } // End of the main Submit conditional. ?> <h1>Change Your Password</h1> <form action="change_password.php" method="post"> <fieldset> <p><b>New Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm New Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Change My Password" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php include ('includes/footer1.html'); ?> When this runs all I get is a blank page and not the message that the password has been changed. As there are no error messages I am not sure where the script is wrong. Can someone tell me where I am going wrong?
  24. I am trying to write some code based on the scripts in Larry Ulmans Book PHP6 & MYSQL 5. When I run the script I get the following error: The config.inc.php is shown below: <?php # config.inc.php /* This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ // Document who created this site, when, why, etc. // ********************************** // // ************ SETTINGS ************ // // Flag variable for site status: define('LIVE', FALSE); // Admin contact address: define('EMAIL', 't.e.hudson@btinternet.com'); // Site URL (base for all redirections): define ('BASE_URL', 'http://www.1066cards4u.co.uk/MFC1066/'); // Location of the MySQL connection script: define ('MYSQL', '\Connect_login.php\\'); // Adjust the time zone for PHP 5.1 and greater: date_default_timezone_set("Europe/London"); // ************ SETTINGS ************ // // ********************************** // // ****************************************** // // ************ ERROR MANAGEMENT ************ // // Create the error handler: function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message. $message = "<p>An error occurred in script $e_file on line $e_line: $e_message\n<br />"; // Add the date and time: $message .= "Date/Time: " . date("j-n-Y H:i:s") . "\n<br />"; // Append $e_vars to the $message: $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { // Development (print the error). echo '<div class ="error">' . $message . '</div><br />'; } else { // Do not show the error: // Send an email to the admin: mail(EMAIL, 'Site Error!', $message, 'From: email@example.com'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. } // End of my_error_handler() definition. // Use my error handler. set_error_handler ('my_error_handler'); // ************ ERROR MANAGEMENT ************ // // ****************************************** // ?> The header is called in the following script: <?php # - login.php // This is the login page for the site. include('includes/SessionManage.php'); SessionManager::sessionStart('login'); require_once ('includes/config.inc.php'); $page_title = 'Login'; include ('includes/header.html'); echo ""; if (isset($_POST['submitted'])) { require_once('includes/Connect_login.php'); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } // Validate the BMFA No: if (!empty($_POST['BMFA'])) { $b = mysqli_real_escape_string ($dbc, $_POST['BMFA']); } else { $b = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } if ($e && $p && $b) { // If everything's OK. // Query the database: $q = "SELECT user_id, first_name, user_level, BMFA_No FROM users WHERE (email='$e' AND pass=SHA1('$p') AND BMFA_No= ('$b')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: $_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'mempage.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <p><b>BMFA No:</b> <input type="text" name="BMFA" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <h2>Forgot your password? Click on this link:<a href="forgot_password.php"target="_blank">Change Password</a></h2> <?php // Include the HTML footer. include ('includes/footer.html'); ?> I have highlighted the line that fails in red. It is used to open the script mempage.php, so I thought I would try opening the script with require, but all I get is a blank screen. Is there a bug in the script that was written by Larry Ulman or is it something is wrong with the way I have modified the script. If that is not the case is there an alternative way of proceeding to the next script? Your help would be appreciated!
×
×
  • 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.