Jump to content

Barand

Moderators
  • Posts

    24,350
  • Joined

  • Last visited

  • Days Won

    796

Everything posted by Barand

  1. P.S. I would recommend a checkbox which the user has to click (check) to verify age. Local storage would have to be set in the javascript. <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> function ageVerified(btn) { if ($(btn).is(":checked") && $(btn).val() == 'Yes' ) { localStorage.setItem('age_verification', 'Yes') } else { localStorage.setItem('age_verification', 'No') } } </script> </head> <body> <form method="post"> I am over 18 &emsp; <input type="checkbox" name="ageverify" onclick="ageVerified(this)" value="Yes"> <br> <input type="submit" name="btnSub" value="Submit"> </form> </body> </html> Alternatively, use a pair of radio buttons. Either way it's a single input... <form method="post"> I am over 18 &emsp; <input type="radio" name="ageverify" onclick="ageVerified(this)" value="No" checked> No &emsp; <input type="radio" name="ageverify" onclick="ageVerified(this)" value="Yes"> Yes <br> <input type="submit" name="btnSub" value="Submit"> </form> Whichever above method you use, the PHP processing would be the same ... <?php if ( ($_POST['ageverify'] ?? 'No') == 'Yes') { echo "User is over 18<hr>"; } else { echo "Under age user<hr>" ; } ?>
  2. You are trying to mix javascript code and PHP. You can't (they run in different places at different times). Why does your form have an input for "yes" and a separate one for "no"?
  3. That is the only selection condition in your query so it displays every record with a non-zero date. You need to put a conditional expression in there to limit it to just the user's records. EG WHERE upv_time_date AND <user id of record> = <id of current user>
  4. Sorry - misread what you were saying - I thought the above was your instruction on what to to.
  5. If he removes the 'Z' timezone indicator it will assume the timestring is his default timeszone (BST) and not UTC, therefore he will need $tstr = '2019-08-13T13:30:00.000'; $dt = new DateTime($tstr, new DateTimeZone('UTC')); // specify UTC timezone to specify it is a UTC time. Otherwise he's back to where he started as his default is Europe/London already.
  6. It does... $tstr = '2019-08-13T13:30:00.000Z'; $dt = new DateTime($tstr); // create UTC datetime object $dt->setTimezone(new DateTimeZone("Europe/London")); // convert to BST echo $dt->format('Y-m-d H:i:s P'); //--> 2019-08-13 14:30:00 +01:00
  7. Given that xml extract $required = ['Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation' ]; $str = <<<XML <Jobs> <Job> <ID></ID> <Name>Job 1</Name> <State>Concept Design</State> <StartDate>2019-02-01</StartDate> <DueDate>2019-10-01</DueDate> <Tasks> <Task> <ID></ID> <Name>Measure Up</Name> <StartDate>2019-07-01</StartDate> <DueDate>2019-07-30</DueDate> </Task> <Task> <ID></ID> <Name>Concept Design</Name> <StartDate>2019-08-01</StartDate> <DueDate>2019-08-31</DueDate> </Task> </Tasks> </Job> </Jobs> XML; $xml = simplexml_load_string($str); // echo '<pre>', print_r($xml, 1), '</pre>'; foreach ($xml->Job as $job) { $state = (string)$job->State; if (!in_array($state, $required)) continue; echo "{$job->Name} — $state — "; foreach ($job->Tasks->Task as $task) { if ($task->Name == $state) { echo $task->DueDate . '<br>'; } } } Output Job 1 — Concept Design — 2019-08-31 EDIT - Alternative method $xml = simplexml_load_string($str); foreach ($xml->xpath("//Job") as $job) { $state = (string)$job->State; if (!in_array($state, $required)) continue; echo "{$job->Name} &mdash; $state &mdash; "; $task = $job->xpath("//Task[Name='$state']") ; echo $task[0]->DueDate . '<br>'; }
  8. Any chance of the full XML? That doesn't seem to match up with your processing.
  9. Don't use form method = GET if you don't want the values to be in the query string.
  10. That has already been answered in the previous post... The query string has been automatically url_encoded prior to submission.
  11. A single query will do the job without any looping. SELECT COUNT(*) as likes FROM products p JOIN product_likes pl USING (product_id) WHERE p.user_id = ?
  12. Perhaps you can make use of the get_class() function
  13. Now you've had time to digest the manual, you should have something like this... $sql = "INSERT INTO `customer` (`FirstName`, `LastName`, `Address`, `Telephone`, `Email`, `SubscribeMailings`) VALUES (?, ?, ?, ?, ?, ?)"; $stmt = $conn->prepare($sql); $stmt->bind_param('ssssss', $Firstname, $Lastname, $Address, $Telephone, $email, $SubscribeMailings); if ($stmt->execute()) { $_SESSION['Customer_ID'] = $conn->insert_id; header('location: report.html'); // if result is true bypasses to the page. } else { $_SESSION['Customer_ID'] = null; echo "details could not be inserted.<br />"; }
  14. As you have a mysqli connection then using the mysqli functions (and not the PDO versions) would be a start. I gave you the link to the manual.
  15. Now you have decided to show the query execution code I can see you are using mysqli and not PDO. The functions are similar but not the same You can find mysqli examples here
  16. Not necessarily. The sites can be spread all over the world. It is the location of the databases that is significant here. If the databases are on the same database server then only a single connection would be required. As I said in my earlier reply, the connection is to the server, not to the database.
  17. I agree with Psycho. Instead of creating all the spreadsheets and emailing them to each salesperson, let them request their data for the month and download the spreadsheet.
  18. Apologies for my my lazy copying of your values from your query when creating the execute statement. The single quotes should, of course, not be there $stmt->execute( [ $Firstname, $Lastname, $Address, $Telephone, $email, $HRD, $SubscribeMailings ] );
  19. Sorry, I thought a name like "$pdo" would indicate it is a PDO connection. Use whatever your connection is in conn.php. (If you are not using PDO then I strongly recommend you change to it)
  20. When you insert the registration and create a new customer save the new id (last_insert_id) in $_SESSION. Then, when you insert the report, insert the customer id saved in $_SESSION. Same goes for existing customers logging in - save their id in $_SESSION. $sql = "INSERT INTO `customer` (`FirstName`, `LastName`, `Address`, `Telephone`, `Email`, `HRD`, `SubscribeMailings`) VALUES (?, ?, ?, ?, ?, ?, ?') "; $stmt = $pdo->prepare($sql); // then, assuming you have validated your input data, // execute the statement passing the data as parameters $stmt->execute( [ '$Firstname', '$Lastname', '$Address', '$Telephone', '$email', '$HRD', '$SubscribeMailings' ] ); // save the new customer id $_SESSION['customer_id'] = $pdo->LastInsertId(); EDIT: my 0.02 worth... Don't create variables for the sake of it. $_POST['Location'] as already a variable so why move its content, unchanged, into yet another one Do not put variables containing user-provided data directly into your queries. Instead use prepared statements and provide the data as parameters. No need to insert those NULLs. Just exclude those fields from the insert and let them default to NULL.
  21. You only need two connections if the databases you want to access are on separate servers. When you make a connection you connect to a server, the database specified is just the default database. Suppose you have a server with two databases When you connect you specify DB1 $conn = mysqli_connect(HOST, USER, PWD, 'DB1'); Now when you want to query tableA you would have $sql = "SELECT cola, colb FROM TableA" This works fine because TableA is in DB1, the default. If, however you want to select something from TableB then all you need to do is specify that it is in DB2 $sql = "SELECT cola, colb FROM DB2.TableB"; You can even mix them in the same query $sql = "SELECT a.cola , b.colb FROM tableA as a INNER JOIN DB2.TableB as b USING (cola) "; To summarize - to access multiple databases on the same server prefix the table names with the database names.
  22. In that case if (isset($_POST['account']) && trim($_POST['account']) != '' && !ctype_digit($_POST['account'])) { $accountErr = "Only numbers are permitted or leave blank"; } else { $accountErr = ""; }
  23. You could use output buffering when generating the page. Save the buffered content to a uniquely named file then output to the screen. Provide a download link to the file.
×
×
  • 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.