Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. position: fixed Setting the position to fixed takes the element out of the normal document flow. That means it does not actually take up space, and instead acts as a separate floating layer. Since it doesn't take up space, your nav bar then becomes the "first" thing in the document, thus showing at the top below your top bar "layer". What you need to do then, is create some space where your top bar should be, such as by giving your body element a top margin (or maybe padding) the same height as your top bar.
  2. Then the script was fundamentally broken on PHP 7.3 as well. The difference is just that PHP 7.3 didn't complain about this mistake as hard. In 7.3 the error would trigger a warning, but your configuration probably did not show those. PHP 8 treats it as a full error now, since the code is improper. So to fix it, you need to either figure out why $return_link is an array, or change the logic to match the previous behavior. The invalid array access would have resulted in a null value on 7.3, making the str_replace do nothing so you might just be able to replace the line with this: $slfile=$directory."/".$this_file; But that is assuming the function is always used incorrectly. If $return_link is valid sometimes, then you will need to do more debugging.
  3. There is a syntax error because I accidentally used a colon instead of semi-colon. If you only get a generic 500 error for such errors, you might want to look into adjusting your development environment to show proper error messages so it's easier to resolve such problems.
  4. All your cookie code there is redundant. session_start manages its own cookie, you don't need to do it yourself. You can control the SameSite value either using the configuration option session.cookie_samesite or the session_set_cookie_params function (before calling session_start). Example: session_set_cookie_params([ 'lifetime' => 0 , 'path' => '/' , 'domain' => '.site.com' , 'secure' => true , 'httponly' => true , 'samesite' => 'Lax' ]): session_start();
  5. That it still not enough information. $return_link is a function parameter, so you need find where the function is being called and determine what value it is being called with and why.
  6. The default height of the body and html elements is not 100%, it's as high as they need to be for the content they contain. If you want them to be 100%, you need to specify that. html, body { height: 100%; }
  7. The error is due to $return_link being some non-scalar value, such as an array or an object. You need to find where $return_link is defined and why it's not a scalar value. There's not enough information in the code given to determine how it should be fixed.
  8. For a basic keyword based search engine, there's nothing really to add to what was shown above. All you need is a list of URLs and the associated keywords. The page table stores details about the page. Each keyword associated with the page gets inserted into the page_keyword table as it's own row. Just to make things slightly more interesting, say you wanted to track of the links a page has. You would add another table storing the ID of the page, an the ID of the linked page. In addition to the above, for each link found in a page, you'd create a new entry in the page table for that link's URL then insert a record in page_link with the original page id and the newly created page id. -- MySQL Script generated by MySQL Workbench -- Thu 13 Apr 2023 12:21:03 AM EDT -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; -- ----------------------------------------------------- -- Table `page` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `page` ( `id` INT NOT NULL AUTO_INCREMENT, `url` VARCHAR(2000) NOT NULL, `title` VARCHAR(100) NOT NULL, `last_accessed` DATETIME NOT NULL, PRIMARY KEY (`id`), UNIQUE INDEX `UQ_page_url` (`url` ASC)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `page_link` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `page_link` ( `page_id` INT NOT NULL, `linked_page_id` INT NOT NULL, PRIMARY KEY (`page_id`, `linked_page_id`), INDEX `fk_page_link_linked_page_id_idx` (`linked_page_id` ASC), CONSTRAINT `fk_page_link_page_id` FOREIGN KEY (`page_id`) REFERENCES `page` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_page_link_linked_page_id` FOREIGN KEY (`linked_page_id`) REFERENCES `page` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `page_keyword` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `page_keyword` ( `page_id` INT NOT NULL, `keyword` VARCHAR(100) NOT NULL, `points` INT NOT NULL, PRIMARY KEY (`page_id`, `keyword`), CONSTRAINT `fk_page_keyword_page_id` FOREIGN KEY (`page_id`) REFERENCES `page` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; -- ----------------------------------------------------- -- Data for table `page` -- ----------------------------------------------------- START TRANSACTION; INSERT INTO `page` (`id`, `url`, `title`, `last_accessed`) VALUES (1, 'kicken.com', 'Kickens World', '2023-04-12 23:54:00'); INSERT INTO `page` (`id`, `url`, `title`, `last_accessed`) VALUES (2, 'phpfreaks.com', 'PHPFreaks', '2023-04-12 23:55:00'); INSERT INTO `page` (`id`, `url`, `title`, `last_accessed`) VALUES (3, 'borobhaisab.com', 'Boro', '2023-04-12 23:56:00'); INSERT INTO `page` (`id`, `url`, `title`, `last_accessed`) VALUES (4, 'php.com', 'PHP', '2023-04-12 23:57:00'); COMMIT; -- ----------------------------------------------------- -- Data for table `page_link` -- ----------------------------------------------------- START TRANSACTION; INSERT INTO `page_link` (`page_id`, `linked_page_id`) VALUES (1, 2); INSERT INTO `page_link` (`page_id`, `linked_page_id`) VALUES (3, 2); INSERT INTO `page_link` (`page_id`, `linked_page_id`) VALUES (1, 4); INSERT INTO `page_link` (`page_id`, `linked_page_id`) VALUES (3, 4); INSERT INTO `page_link` (`page_id`, `linked_page_id`) VALUES (2, 4); COMMIT; -- ----------------------------------------------------- -- Data for table `page_keyword` -- ----------------------------------------------------- START TRANSACTION; INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (1, 'usa', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (1, 'phone', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (1, 'apps', 2); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (1, 'tutorial', 2); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (2, 'uk', 1); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (2, 'php', 4); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (2, 'apps', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (2, 'price', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (3, 'tutorial', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (3, 'book', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (3, 'php', 2); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (3, 'usa', 3); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'PHPs', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'books', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'united states america', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'prices', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'python', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'book', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'apps', 5); INSERT INTO `page_keyword` (`page_id`, `keyword`, `points`) VALUES (4, 'usa', 5); COMMIT; SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; DB Fiddle example.
  9. I'm not going to spend time writing SQL that I don't believe should be written in the first place, but if you insist on pursing this, I'll at least give you a hint. CASE
  10. You won't learn anything useful about SQL pursuing this design because the design is fundamentally flawed and directly opposed what SQL is designed to do. My answer is that you don't. I'm sure there is a way for it to be done, but doing so would teach you nothing useful. The correct solution to your problem is to re-design your table structure, then use SQL as it's intended to be used rather than fight against it trying to make a poor design work. This shows yet another potential reason why your design is flawed. Why do you have multiple rows for the same link? If the answer is "To have more than 4 key words" then that's wrong. The multi-table solution gives you the ability to have an unlimited number of keywords per link.
  11. If you want to measure the time from when the page starts processing until the page is loaded in the browser, you cannot do that strictly with PHP. You'd have to capture the start time at the start of your PHP script, and the finish time via JavaScript's onload event. This metric isn't really all that useful though. How long it takes the page content to be loaded and processed will depend on the user's network speed which is beyond your control. If you're looking to optimize your page load times, you should be looking at the PHP processing and browser loading/processing separately rather than as a combined single load time. You could measure the processing time of your script in PHP by capturing the start time at the beginning of your script, then the ending time when your script ends. This metric would tell you if your PHP is slow to process, which you could use to determine if you need to improve areas of your code. Actual code profiling over just a simple load time would be better if this is your goal. For the browser side of things, the browser developer tools include profiling/performance tools to measure your pages resource load times, rendering times, etc.
  12. Do you actually need the separate classes though, or could you just use something like :nth-of-type? .quizContent > div:nth-of-type(1) { color: pink; } .quizContent > div:nth-of-type(2) { color: red; } .quizContent > div:nth-of-type(3) { color: black; } .quizContent > div:nth-of-type(4) { color: blue; }
  13. That code is doing things the hard way. HTML has a template tag for a reason. Use your PHP code to generate a template row in a template tag. The your JS only needs to clone that row and add it to the table. For example: Template: <template id="row-template"> <tr> <td></td> <td> <select class="background" name="Department[]"> <option value="">Department</option> <?php $qry = mysqli_query($conn,"SELECT DISTINCT Brand FROM model ORDER BY Brand ASC"); while($row = $qry->fetch_assoc()) { echo "<option"; if(isset($_REQUEST['Department']) and $_REQUEST['Department']==$row['Brand']) echo ' selected="selected"'; echo ">{$row['Brand']}</option>\n"; } ?> </select> </td> <td><input type='text' name='category[]'></td> <td><input type='text' name='sub_category[]'></td> <td><input type='text' name='model[]'></td> <td><input type='number' name='qty[]'></td> </tr> </template> JS: const template=document.getElementById('row-template'); const tbody=document.getElementById('tbody'); let itemCount=0; function addItem(){ const newRow = template.content.cloneNode(true); const firstTd = newRow.querySelector('td:first-child'); firstTd.textContent=++itemCount; tbody.appendChild(newRow); }
  14. You are not passing the ID of the record to delete in your delete request, so your script is returning the error text "Error: 'id' parameter is missing in the request." Your Javascript code is expecting the response to be JSON data. Your error message text is not JSON data, so trying to parse it as JSON throws an error.
  15. This was a mistake. If you find your self making multiple columns for the same type of data, what you really want is another table. A more proper change would have been to create a second link_keywords table with a reference to the link ID. Like so: links: id|domain|url|title link_keyword: link_id|keyword|points With that setup, your query would then be simple, like: select * from links inner join link_keyword on link_keyword.link_id=links.id where link_keyword.keyword = ? order by link_keyword.points desc If you want to have a global list of keywords and point values that is shared across all your links, then you'd have three tables, such as: links: id|domain|url|title link_keyword: link_id|keyword_id keywords: id|keyword|points The adjust the query with another join as appropriate.
  16. upper-case N Name is not the same as lower-case n name.
  17. The data structure you are sending is: const userData = { firstName: firstName, lastName: lastName, email: email, mobileNumber: mobileNumber, password: password, }; While the data structure you are reading is: $name = $data['name']; $email = $data['email']; $mobileNumber = $data['mobileNumber']; $password = $data['password']; Notice the difference in the fields?
  18. You do not use single-quotes around DB identifiers like the DB name, table name, column names, etc. Single quotes are only for string literals. Generally you simply do not quote the identifiers at all, there's no reason too unless you're trying to use reserved words or restricted characters (which you shouldn't do anyway). If for some reason you want to quote the identifiers, you do so using back-ticks (`).
  19. The amount of bytes used to encode characters, and as a result the total amount of characters that can be encoded. 10.10.1 Unicode Character Sets
  20. Presumable that would be in whatever .css file you imported into your page to make those classes available to you in the first place. You could just use the browser's dev tools to inspect the elements and see the rules and properties applied too. Have you looked over the documentation?
  21. You can use composer stuff, you'd just need to add the "composer/composer" package as a requirement to your project. If all you need is the class map stuff, that is it's own component (composer/class-map-generator) so you could include just it instead.
  22. If you need an actual file path, then tempnam() is the way to go. tmpfile is for if you need a temporary file resource, just a shortcut essentially for doing fopen('php://temp', 'w+');. As an example, I have a html2pdf class that generates some temp files and calls an external program to generate the PDF. This is how that is coded (roughly). public function generatePdf(){ $pdf = null; try { $source = tempnam(sys_get_temp_dir(), 'htmlpdf'); $destination = tempnam(sys_get_temp_dir(), 'htmlpdf'); file_put_contents($source, $this->html); $cmd = $this->createCommandLine($source, $destination); exec($cmd, $output, $ret); if ($ret !== 0){ throw new \RuntimeException('Failed to generate PDF with command [' . $cmd . '] Output: ' . implode(PHP_EOL, $output)); } $pdf = file_get_contents($destination); } finally { unlink($source); unlink($destination); } return $pdf; } Generate the two temporary file locations, execute the command, then read the content out of the file. The temporary files are then cleaned up using a finally clause which will run whether the function when the function exits, whether that be by a successful return or by throwing an exception.
  23. You're probably having issues with SQL Injection due to putting your raw values directly into your query. You should be using prepared queries and binding the values as parameters, not inserting them into the query text directly. I would also suggest you look into using PDO instead of mysqli. It's a cleaner and easier to use API, particularly with prepared queries.
  24. Why do you think it wouldn't work for other errors? It says in the manual It doesn't say it throws on invalid username/password, it says it throws on failure. Invalid username / password is only one of many reasons why the connection attempt might fail.
  25. You have id="btn" twice in that code, which is invalid. ID's must be unique across the elements. You also never actually call your hideButton function anywhere. You need to apply it to some sort of event, such as the onclick of the button, if you want to have it run. This has a PHP syntax error due to the single-quotes around none, you need to escape them using a backslash. This version has a HTML syntax error because of the single quotes as well, as the end up closing the attribute early. Your onclick attribute value is just this.style.display=, which is invalid javascript.
×
×
  • 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.