Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Strider64

  1. I personally like using the Fetch API as it's pretty straight forward and pretty darn easy to use (once you get the hang of coding it): Here's an example from my contact page: /* Success function utilizing FETCH */ const sendUISuccess = function (result) { //console.log('Result', result); if (result) { d.querySelector('#recaptcha').style.display = "none"; submit.style.display = "none"; notice.style.display = "grid"; notice.textContent = "Email Successfully Sent!"; notice.style.color = "green";
  2. Do a echo "<pre>" . print_r($result, 1) . "</pre>"; die(); to see if you are getting any results.
  3. $pwd = password_hash($data['password'], PASSWORD_DEFAULT); unset($data['password']); try { $query = 'INSERT INTO users (fullName, username, status, password, security, email, date_added) VALUES (:fullName, :username, :status, :password, :security, :email, Now())'; $stmt = Database::pdo()->prepare($query); $result = $stmt->execute([':fullName' => $data['fullName'], ':username' => $data['username'], ':status' => $data['status'], ':password' => $this->pwd, ':security' => 'newuser', ':email' => $data['email']]);
  4. There's is a way check the "inside" of an image file $contents = file_get_contents($file['tmp_name']); $position = strpos($contents, '<?php'); return $position !== false; HOWEVER, it's a memory hog and doesn't work very good for large image files as you would need something more robust than the strpos() function. I personally don't allow image uploading other than myself who I trust. 😄
  5. To me that would be more ideal for a client side web app (like JavaScript) than a server-side app (PHP). They wouldn't have to use the back button at all and you could even use JavaScript, Ajax and PHP if you want to use a MySQL table. To give you an idea here is an example of a trivia game that I wrote for my website - https://www.miniaturephotographer.com/game.php I'm still developing it, but it works pretty darn good and you can do all sorts of things to it.
  6. You're not echoing out the content <h4><?php the_title(); ?> </h4> should be <h4><?php echo the_title(); ?> </h4> /* or this */ <h4><?= the_title() ?> </h4>
  7. e.preventDefault() will stop the HTML button from firing: submit.addEventListener('click', (e) => { e.preventDefault(); sendEmail.phone = phone.value; sendEmail.website = website.value; sendEmail.response = submit.getAttribute('data-response'); if (sendStatus.name && sendStatus.email && sendStatus.comments) { saveRequest(sendUrl, sendUISuccess, sendUIError); } else { notice.style.display = "block"; notice.textContent = "Name, Email, and Message Required!"; } }, false);
  8. If the code doesn't work, but the only solution is to use arrays then learning about arrays is probably only option? There's a reason why the code stopped working and that is you added extra conditions to the script. Instead of single images there are now multiple images? (I'm assuming and you know what they say about assuming. 😃) Learning arrays isn't that tough. It is one of the first things that is taught in any coding language.
  9. Well, it's not actually cropping, but resizing function that I wrote and I have been testing it out on my website. So far it's been working like I expect it to. Though I imagine you could modify the script to do cropping? <?php function imageResize($imageSrc, $imageWidth, $imageHeight, $newImageWidth, $newImageHeight): GdImage|bool { $newImageLayer = imagecreatetruecolor($newImageWidth, $newImageHeight); imagecopyresampled($newImageLayer, $imageSrc, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $imageWidth, $imageHeight); return $newImageLayer; } function resize($file_tem
  10. or you could simply have a small function of some kind to use a full name: function fullname($user) { return $user['firstname'] . " " . $user['lastname']; }
  11. If you are not using Fetch then you need to parse the data: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.name; } }; xmlhttp.open("GET", "json_demo.txt", true); xmlhttp.send();
  12. The methods/functions in the DbBox class to me is redundant unless you are going to override them, but like requinix stated "really, really, really vague question" to help with. I use the Active Record Design Pattern and those two classes would just be silly to me.
  13. Ooops read it wrong ..... please delete 😃
  14. 🤔 Hmm? Something tells me that isn't true. 🤥😔
  15. I have been updating my website to include the Active Response Design pattern using PHP pdo. I have most to the pdo done with a few minor refinements and improvements. If you want to get some ideas or inspiration check out my GitHub repository : https://github.com/Strider64/Miniature01282021 I know there's better out there, but it' not to bad for a person who is 56 that has only been programming in PHP the last 6-7 years (though I have previous coding experience in other languages).
  16. I would personally just do it silently with an unique constraint in MySQL and not advertising it too much to users. The more you broadcast it or let it be known that an username exists the more like they will attack your website. I'm not saying NOT to do it, but simply say "username can't be used at this time", "Choose a different username" or something more vague than that after the user attempts to registers. It's usually not that big of deal having to come up with a different username as you can save all the other registration info (except password) back on the HTML form as a convenience to
  17. Exactly what the error says $data is a string not an array. You also have other errors.
  18. This is how I do it: My Database Class: <?php namespace Miniature; use PDO; class Database { private $_connection; // Store the single instance. private static $_instance; // Get an instance of the Database. // @return Database: protected static function getInstance(): Database { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; } public static function pdo(): PDO { $db = static::getInstance(); return $db->getConnection(); } // Constructor -
  19. I will chime in with my thoughts. I bet most of your website could be fixed to look good on mobile devices by doing some CSS tweaks. It doesn't have to look the greatest as all it needs to look good. Here's what I do, first for all browsers including mobile: /*-------------------------------------------------------------- Basic responsive layout for all browsers: --------------------------------------------------------------*/ .site { background-color: #fff; max-width: 75em; margin: 0 auto; } Then inside a media query for modern browsers (Firefox, Chrome for PCs)
  20. My opinion using grid and flex together would do the trick. Though you could even even accomplish with just flex, but it gets a little tricky if you have to change the number of columns. Though you can fix that problem using JavaScript.
  21. Well, I find syntax bugs to be a pain when you have logic errors on top of them. You fix all the syntax bugs and you code doesn't work the way you expect it to then you feel like you just wasted a couple hours of work, plus you feel like banging you head against the desk. The best way to learn PHP in my opinion is to learn the code syntax properly by going to php.net and following tutorials. An IDE is just away to debug syntax errors more quickly in order for you to concentrate on the logical errors. That's my opinon.
  22. I don't know if I'm on the right track and I use DateTime(), but I'm sure it can be done with date as well. <?php $firstMonday = new DateTime("January 1, 2021", new DateTimeZone("America/Detroit")); if ($firstMonday->format("l") === "Sunday") { $firstMonday->modify("last Monday"); echo $firstMonday->format("F j, Y -l") . "<br>"; } else { $firstMonday->modify("Monday"); echo $firstMonday->format("F j, Y -l"); }
  23. I agree learning a basic programming language services is a great foundation in learning other programming languages. I'm 56 years and when I first was learning programming I was had a class in Pascal (I think that was the language) that set the tone for other languages. After learning the first language I would suggest learning C+ as that programming language is very similar to a lot of languages that will make you say I seen that before and then realize it was C+. It doesn't have to be that in-depth learning C+ as getting the basics would be enough in my opinion.
  24. Personally I just redirect to another php file if a certain about of text should only be displayed. I do it like the following: public function getIntro($content = "", $count = 200, $pageId = 0) {; $this->content = (string) $content; return substr($this->content, 0, (int)$count) . '<a class="moreBtn" href="mainArticle.php?page=' . (int)$pageId . '"> ...more</a>'; } If I want to have is stay on the same page I simply would just introduce vanilla javascript. (Which I might after I get done overhauling my website) I just simply display a page
  25. Personally I wouldn't start off learning PDO by doing try-catch statements as in my opinion will cause more confusion than it is worth. Simply have error reporting turned on to catch the errors. I personally don't like writing foreach statements that way, I would write it something like the following: <?php foreach ($result as $text) { echo '<blockquote>'; echo '<p>' . htmlspecialchars($text['joketext']) . '</p>'; echo '</blockquote>'; } ?> as for the pdo I would do something like the following: $db_options = array( /* i
  • 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.