Jump to content

Strider64

Members
  • Posts

    473
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by Strider64

  1. I personally find it easier to store the path and the filename in the database table, for example - assets/large/img-photos-1554932472.jpg. Then I simply do <img src="<?php echo $image ?>" width="478" height="1034" alt="">
  2. Well I would check the captcha first then process the email. Here's my little script that does that -> /* The Following to get response back from Google recaptcha */ $url = "https://www.google.com/recaptcha/api/siteverify"; $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL); $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer); $recaptcha_data = json_decode($response); /* The actual check of the recaptcha */ if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { $success = "Mail was sent!"; $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $send = new Email($data); } else { $success = "You're not a human!"; // Not of a production server: } The $send = new Email($data) is my email process, if your form was working before then just do something like that.
  3. Well, if you are GETTING then you can just easily SET the data. If you set the data then you can easily save the data. Doing it this way class userModel{ private name; private email; /*lots more properties for user */ public function getName(){ return $this->name; } public function getEmail(){ return $this->email; } } would be more secure in my opinion.
  4. A side note, most people get annoyed entering (or choosing) more than 8-10 fields on one page, so if the form is huge with a lot of input fields it is best to split the form and have it on multiple web pages. So that might give you an idea if you should separate the code in a separate file?
  5. It's still a work-in-progress but I'm developing a registration and login tutorial and you can find it here: https://github.com/Strider64/php-registration-tutorial The registration portion works (though I want to rework it a little) and I need to do the login portion of the tutorial. All the files can be found there.
  6. You really should have error reporting turned on and an IDE that will flag syntax errors (it'll make life much easier). I would also separate the query from the prepare. Here's an example of mine -> $query = 'INSERT INTO trivia_questions (question, answer1, answer2, answer3, answer4, correct, category, play_date) VALUES (:question, :answer1, :answer2, :answer3, :answer4, :correct, :category, NOW())'; $stmt = $pdo->prepare($query); That way you can easily debug the script. Everyone who writes code gets syntax errors which are easily fixable and the less time you spend on them the more you can concentrate on the baddies (logic errors).
  7. Trying to be nice as possible and not trying to sound like a poster on a different forum, but your HTML itself needs a lot of working itself. I believe having a firm grasp on HTML, CSS and JavaScript (Basic pure javascript) will make the learning curve easier. I agree with ginerjm to do the email form in php first then it will be simple to add JQuery or Javascript to the form. Here's a contact form that I did for a Github Repository: https://github.com/Strider64/html-contact-form <form id="contact" action="index.php" method="post" autocomplete="on"> <fieldset> <legend><?php echo (isset($message)) ? $message : 'Contact Details'; ?></legend> <label for="name" accesskey="U">Your Name</label> <input name="name" type="text" id="name" placeholder="Enter your name" required="required" /> <label for="email" accesskey="E">Email</label> <input name="email" type="email" id="email" placeholder="Enter your Email Address" required="required" /> <label for="phone" accesskey="P">Phone <small>(optional)</small></label> <input name="phone" type="tel" id="phone" size="30" placeholder="Enter your phone number" /> <label for="website" accesskey="W">Website <small>(optional)</small></label> <input name="website" type="text" id="website" placeholder="Enter your website address" /> </fieldset> <fieldset> <legend>Your Comments</legend> <div class="radioBlock"> <input type="radio" id="radio1" name="reason" value="support" checked> <label class="radioStyle" for="radio1">support</label> <input type="radio" id="radio2" name="reason" value="advertise"> <label class="radioStyle" for="radio2">advertise</label> <input type="radio" id="radio3" name="reason" value="error"> <label class="radioStyle" for="radio3">Report a Bug</label> </div> <label class="textBox" for="comments">Comments</label> <textarea name="comments" id="comments" placeholder="Enter your comments" spellcheck="true" required="required"></textarea> </fieldset> <input type="submit" name="submit" value="submit"> </form> and here's the css to the form: form#contact { display: block; width: 100%; max-width: 800px; height: auto; background-color: #ebdb8d; padding: 20px; margin: 0 auto 20px; } form#contact fieldset { border: 2px solid #2e2e2e; padding: 30px; margin-bottom: 20px; } form#contact fieldset legend { font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif; font-size: 1.4rem; color: #2e2e2e; padding: 0 5px; } form#contact fieldset label { float: left; display: block; width: 100%; max-width: 220px; height: 30px; font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; line-height: 30px; color: #2e2e2e; text-align: right; padding: 0 10px; } form#contact fieldset input { clear: right; display: block; width: 100%; max-width: 250px; height: 30px; border: none; outline: none; font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; color: #2e2e2e; padding: 0 5px; margin-bottom: 10px; } form#contact fieldset .radioBlock { display: block; width: 100%; max-width: 100%; height: auto; margin: 0 auto; } form#contact fieldset input[type=radio] { display: none; margin: 10px; } form#contact fieldset input[type=radio] + label.radioStyle { display: inline-block; width: 33.33333333333%; height: 45px; margin: -2px; text-align: center; text-transform: capitalize; cursor: pointer; color: #fff; background-color: #000; border: 2px solid #ffa; line-height: 45px; margin: 10px auto 0 auto; } form#contact fieldset input[type=radio] + label.radioStyle:hover { background-color: #aaa; color: #ffa; } form#contact fieldset input[type=radio]:checked + label.radioStyle { background-image: none; color: #ffa; background-color: #aaa; } form#contact fieldset label.textBox { clear: both; text-align: left; padding: 0; margin-top: 20px; } form#contact fieldset textArea#comments { resize: none; border: none; outline: none; clear: both; display: block; width: 100%; max-width: 660px; height: 400px; font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; padding: 10px; } form#contact input[type=submit] { outline: none; border: none; display: block; width: 100%; max-width: 120px; height: 40px; cursor: pointer; border: 3px solid #ffa; background-color: #000; font-family: Arial, Helvetica, sans-serif; font-size: 1.2rem; color: #fff; text-transform: capitalize; margin-left: 640px; } form#contact input[type=submit]:hover { color: #ffa; background-color: #aaa; } Granted it's not a fancy styling with CSS, but it could be easily modified to be so. A great website site to practice CSS is : http://www.csszengarden.com/ HTH JOHN P.S. There are a lot of great websites and books on HTML/CSS, plus some of them are even free.
  8. You would be better to go to php.net (The direct source for php into) and check over the functions. People even give examples on them. They (php.net) even provide you where you can download a free database to check MySQL functions (use PDO or mysqli) and it called world.sql (I believe). What I do is have a folder (I call it phpSandbox) where I put all my learning and testing scripts in. Here's just one of many scripts I have written over the years. <?php include 'lib/includes/connect/connect.php'; $db_options = [ /* important! use actual prepared statements (default: emulate prepared statements) */ PDO::ATTR_EMULATE_PREPARES => false /* throw exceptions on errors (default: stay silent) */ , PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION /* fetch associative arrays (default: mixed arrays) */ , PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ ]; if (filter_input(INPUT_POST, submit)) { $pdo = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=world;charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options); $query = 'SELECT Name, CountryCode, District, Population FROM city WHERE CountryCode=:CountryCode ORDER BY District'; // Set the Search Query: $stmt = $pdo->prepare($query); // Prepare the query: $result = $stmt->execute([':CountryCode' => filter_input(INPUT_POST, countryCode)]); // Execute the query with the supplied user's parameter(s): } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Database Search</title> <link rel="stylesheet" href="lib/css/reset.css"> <link rel="stylesheet" href="lib/css/grids.css"> <link rel="stylesheet" href="lib/css/searchstyle.css"> </head> <body> <div class="container seachBackground"> <form id="searchForm" action="search.php" method="post"> <label for="searchStyle">search</label> <input id="searchStyle" type="text" name="countryCode" value="" placeholder="Enter Country Code (For Exampe : USA)..." tabindex="1" autofocus> <input type="submit" name="submit" value="submit" tabindex="2"> </form> </div> <div <?= $result ? 'class="turnOn" ' : 'class="turnOff" '; ?>> <table id="search" summary="Cities Around the World!"> <thead> <tr> <th scope="col">City</th> <th scope="col">Country Code</th> <th scope="col">District / State</th> <th scope="col">Population</th> </tr> </thead> <tbody> <?php if ($result) { while ($record = $stmt->fetch()) { echo "<tr>"; echo '<td>' . $record->Name . "</td>"; echo '<td>' . $record->CountryCode . "</td>"; echo '<td>' . $record->District . "</td>"; echo '<td>' . $record->Population . "</td>"; echo "</tr>"; } } ?> </tbody> </table> </div> </body> </html> I personally would NOT go to a forum and grab scripts that other people are asking help on, for you don't know where exactly they are at with their problem(s) or that if they are committed in resolving their problem. I have seen many people who post for help on their problems and never acknowledge they have resolved the issue. Do you really want to copy a script from someone like that? I know I wouldn't. Another thing that I have learned over the last couple of years, is while you might belong to many help forums the key to getting a resolution is to post on only ONE forum and have plenty of patience. People who answer you questions are doing out of their desire to help people and they too have other important things that have to get done first. Someone will eventually answer you question. One last thing make your topic relevant to your problem, something like "I am having a problem with updating in PHP PDO?". While that might even be a little vague, it's way better than "HELP! I Have a Problem".
  9. $query = "SELECT count(1) FROM myTable WHERE score > :user_score"; $stmt = $pdo->prepare($query); $stmt->execute([':user_score' => $user_score]); $ranks = $stmt->fetchColumn(); Why not simply do something like the above? (Pull the score separately from the query is what I would do) That might have to be >= rather than > ?
  10. I think you're confusing what is clickable and what is not: https://jsfiddle.net/Strider64/db8NB/ While that isn't the same thing it should show you what I'm talking about. $(function () { var myButton1 = $('.myButton1'), // The Button: box1 = $('.box1'), myButton2 = $('.myButton2'), box2 = $('.box2'); myButton1.on('click', function () { $(this).toggleClass('off'); if ($(this).hasClass('off')) { moveRight(); // Animate Box to the Right: } else { moveLeft(); // Move Box back to the Original Position: } }); myButton2.hover(function () { box2.animate({ 'left': '300px' }); $(this).css('background-color', 'orange'); }, function () { box2.animate({ 'left': 0 }); }); function moveLeft() { box1.animate({ 'left': 0 }); } function moveRight() { box1.animate({ 'left': '300px' }); }
  11. I also add that php's DateTime Class (server side) is more robust in my opinion in handling date and time. I simple little Ajax script to pull that into JavaScript and display (maybe a little fine tuning with JS).
  12. What I do is put all my output as arrays and send them down to a json function and any errors are thrown to an error function then to output. Like so -> <?php require_once 'lib/includes/utilities.inc.php'; use website_project\trivia_game\OutputQA; /* Makes it so we don't have to decode the json coming from JQuery */ header('Content-type: application/json'); $gamePlay = new OutputQA(); $id = filter_input(INPUT_POST, 'id'); if (isset($id)) { $data = $gamePlay->readQA($id); if ($data) { $output = $data[0]; output($output); } else { $output = 'eof'; errorOutput($output, 410); } } $q_num = filter_input(INPUT_POST, 'q_num'); $answer = filter_input(INPUT_POST, 'answer'); if (isset($q_num) && isset($answer)) { $result = $gamePlay->checkDailyTen($q_num, $answer); if ($result) { output($result); } else { $output = ['eof' => TRUE, 'message' => 'There are no more questions']; errorOutput($output, 410); } } /* * Set error code then send message to Ajax / JavaScript */ function errorOutput($output, $code = 500) { http_response_code($code); echo json_encode($output); } /* * If everything validates OK then send success message to Ajax / JavaScript */ function output($output) { http_response_code(200); echo json_encode($output); } It just something that keeps me thinking straight....it might help
  13. There a plenty of books that just deal with design patterns, though boring can be useful. An author like Larry Ullman a good PHP author can show you how to get going in OOP and I know Ullman will even recommend a few of these other authors of design patterns. What I do with something that you are trying to implement is break it down to its simplest core. In this case you want to write a user's registration. Well that requires interactivity with a database table of some sort. The first thing you will have to do is Create the db Table, next it would be nice to be able to Read from the db Table, after that it would be nice to be able to edit certain fields so you want to be able to Update the db Table, and finally you want to give the administrator (and maybe the user themselves) the ability to Delete the record for the db Table. So what do we have? We have CRUD and stick a interface on it then you get iCRUD. <?php namespace login_project\database; /* The iCRUD interface. * The interface identifies four methods: * - create() * - read() * - update() * - delete() */ interface iCRUD { public function create($data); public function read(); public function update($data); public function delete($id=NULL); } While this a basic interface that I am sure pales in comparison to other interfaces, the purpose of it to force you to build your class in a precise manner and you'll find that it can be used for other than an user's registration class. If you have a good IDE then you have an added bonus for it will give you hints and turn green on methods that you have correctly implemented in your class. Though like I said Larry Ullman or other authors of design patterns will be able to you better explanation than I.
  14. I know I going to get boos , but what about using a table? It looks like a perfect candidate for it's mainly data you're playing around with. An contrary to current thinking - Tables can be stylized nicely with CSS.
  15. Also the standard date format for MySQL is Y-m-d H:i:s not Ymd. That could be part of your problem?
  16. I agree with the above for that a good way in not getting trip up with boolean comparisons. A simple trick that I do when writing if statements is I use === instead of == that way if I forget an equal sign it'll still work (someone told me this a long time ago when I was asking for help). This will work 95% of the time, but there are some instances that you can't use a direct comparison (exactly the same value) and in the situation you need either to use the == or === depending in whatcha doing, but I really haven't found that to be a hiccup. I don't do much regex and I am guessing that would be where that comes into play?.
  17. I have a PHP book by Larry Ullman and I don't ever remember teaching spaghetti-code code? I would be very surprised if Larry was doing that.....
  18. If the date is coming from a form most people use post for it's more secure, so it would be better to use $_POST['time_input']. Though to be honest I have I'm still a little confused on the original poster's post and this in what the OP means set the time in the form? Does it want to be incremented one hour before being made a selection in the form (giving the user an option) or be already set?
  19. You could manipulate the css with javascript, but why would you? Answer: You basically wouldn't unless you wouldn't, but there are small exceptions to the rule (Like developing an online quiz). It also cumbersome to use JavaScript to modify the css, when it can be directly changed in css and I would bet most developers add/remove css classes (or ids) than manipulate the css directly in javascript.
  20. I been using Netbeans since I was mainly a PC user, but I switched over to the iMac and found it even easier to setup. The one downfall that I found writing PHP under Windows is that Windows isn't unix based thus setting up Netbeans (more like the local server in setting it up) takes a little bit of workarounds and/or knowing a little bit of DOS (Something I knew since DOS 3.1 LOL ). However, once you get it setup there should be no problems and things become second nature; however, I found setting up a website on a remote server sometimes a little baffling until I remember I design/developed on a Windows based computer.
  21. If you want to figure out duration of time you need actually timestamps like already stated or the Date and Time. Look into the DateTime class at php.net for it has a lot of built in functions that can be used, so you don't have to reinvent the wheel. Here's an example -> <?php date_default_timezone_set("America/Detroit"); $start = '2016-09-11 12:45:00'; $end = '2016-09-13 12:59:52'; $date1 = new \DateTime($start); echo $date1->format("F d, Y"); $date2 = new \DateTime($end); $diff = $date1->diff($date2); echo "<pre>" . print_r($diff, 1) . "</pre>";
  22. or just use label after the input statement and it perfectly HTML $attr_input .= '<label for="tracker">' . $entry_instructions . '</label>';
  23. You might want to check this out -> https://github.com/js-cookie/js-cookie
  24. What happens if someone disables Javascript? Can they bypass the checks? I personally do the validation checks using PHP that way I know nothing gets bypassed. Then if I wanted to add I can add Javascript/JQuery validation after I get the php validation working.
  25. You should be posting a password....leave it blank or put ***** as a replacement.
×
×
  • 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.