Jump to content

jodunno

Members
  • Posts

    321
  • Joined

  • Last visited

  • Days Won

    5

jodunno last won the day on September 18 2024

jodunno had the most liked content!

1 Follower

About jodunno

  • Birthday 01/01/1973

Profile Information

  • Gender
    Male
  • Location
    Berlin, Germany
  • Interests
    Nature and Biology, Programming and Web Development, Forensic Science, sports

Recent Profile Visitors

5,891 profile views

jodunno's Achievements

Advanced Member

Advanced Member (4/5)

17

Reputation

8

Community Answers

  1. Hi CBG, @mac_gyver actually posted the solution that you have chosen. And i want to say that mac_gyver and maxxd are better programmers and they have more experience than i do in this field. However, i disagree with any solutions that create a bunch of if branches because every step that a program takes can really slow it down. I definitely disagree that you cannot check it all at once. Personally, i recommend using the tools in the PHP toolbox to your advantage. I would do the following and be done with it: <?php $p = 'Yes'; $d = 'No'; $c = 'No'; $o = 'No'; $pinary = [$p] === ['Yes']; $nerror = [$d, $c, $o] === ['No','No','No']; if ($p && $nerror) { echo 'error'; exit; } echo 'No errors detected'; ?> then i would unset $pinary and $nerror to spare memory (even though 100% of coders would tell you not to do that). My point, is that you can check it all at once but you could do it differently. I would define an error and simply check if it is true.
  2. Hi CBG, Logical switches do not work like spoken words and it is easy to misunderstand them. What you really want to check is that if any one of d,c,o is yes, then error. But PHP is obeying your instructions by stopping when anyone of them is No. You need to switch the OR to an AND and it will catch the one Yes that is not allowed: <?php $p = "Yes"; //yes is different than Yes $d = "No"; $c = "No"; $o = "No"; if ($p === "Yes" && $d !== "Yes" && $c !== "Yes" && $o !== "Yes") { echo "error"; exit; } echo 'no errors'; ?> which will display an error if all three (d,c,o) are No. Otherwise, the code will display no errors. but what are you doing when a lowercase y is used? yes instead of Yes. maybe you should also use lowercase and compare with strtolower().
  3. Hi Rhaoma, umm, I didn't imply or intend to imply that you write "sh1t code". I am not exactly a top notch coder. I actually write some ugly Spaghetti code at times. Noone would say that my coding skills are that to be admired, so i definitely do not insult other coders. Not sh1t code. I just see a 100 and i wonder what you are doing but i do not know how i solved any problems for you. If your code is working and you are happy with the code, then i suppose that you have solved your own problem. Otherwise, let us know if you are still having trouble. The forum has alot of pro php coders. Sometimes people get busy and may not respond immediately but someone will eventually come along and help. I hope that you have a pleasant day, John
  4. where in the hell-p do you get 100 for the Content-Length? what is that supposed to mean? 100 what? sheep? usually, programmers let php determine the size of something. filesize, strlen() etc. I think that you should take a closer look at your code.
  5. Python? in a php forum? forums.phpfreaks.com. I do not see the name python in the domain. I hate python and it is not necessary. PHP can solve this problem and any other problem. Please see the solution posted by Barand: Furthermore, isolating the actual question is not a problem if the array is designed/structured correctly from the start. So a better reply would be a suggestion other than that already posted by Barand. one could simply rewrite the array using a loop, then regex is not even necessary. In other words, fix the array to hold three components instead of a single string (a problem created by bad array design/structure). So, to me, the problem is the array. one could use php to rebuild the array or just use the following code to get what you want from the array (however Barand has already posted a solution that works): <?php //add a loop to build a new array or just display the question of the current array (but in latter case, the solution by Barrand is better) //to repeat Requinix: be sure that the questions actually contain the filtered characters or you will further complicate the matter. $qlist = array (); $qlist[0] = "[Question - Geography Chapter2] How would you describe humans' relationship with the physical environment? (Page 42)"; list($source, $question) = explode("]",$qlist[0]); //echo "<p>$question</p>"; list($question, $page) = explode("(",$question); echo "<p>$question</p>"; ?>
  6. regarding background-size: i wonder if actually specifying a size is not working? if i understand you correctly, you want to force a background image to fit into its container, yes? I made a crop of a photo of mine depicting the female genitalia of Phaonia rufipalpis. I will attach the crop for testing my code. I use background-size to make it fit the container. Is this not what you want? <!DOCTYPE html> <html> <head> <title>CSS background-size</title> <style> div.container { display: block; margin: 0 auto; padding: 0px; width: 400px; height: 400px; border: solid 1px #000000; background-image: url('s263x200.jpg'); background-repeat: no-repeat; /* background-size: 400px 400px; */ background-size: 100% 100%; } div.text { position: relative; top: 93%; padding: 5px; background: rgb(0,0,0,0.2); color: #ffffff; text-align: center; } </style> </head> <body> <div class="container"> <div class="text">background-size: 100% 100%;</div> </div> </body> </html>
  7. that is where the expression Spaghetti code comes into play (weaving in-and-out of a language creates a noodle like appearance) and fortifies why it should be avoided if posible. Once you exit php, how is php to know that the else belongs to the previous if without further clarification? when php encounters the else, it responds with the error because an if does not precede it in the same section of code. Adding curly braces removes the ambiguity, or using end if as suggested by Gizmola.
  8. Hi Paul-D, you are moving in-and-out of php (spaghetti code). You will need to use the curly braces in your branch, so that php knows that the else belongs to the previous if statement. You can echo or print by using a single-quote, double-quote combo: echo 'i can use "double-quotes" within single quotes'; <?php session_start(); $_SESSION["DE_Retain"] = 0; if(!empty($_SESSION["DE_Retain"])) { echo 'show if'; } else { echo 'show else'; } $x = 1; if ($x == 1) { ?> x = 0 <?php } else { ?> x = 0 <?php } ?> you should avoid spaghetti code whenever possible. Sometimes it is okay but an entire php script written with spaghetti code is very difficult to follow and you will find yourself asking alot of questions in phpfreaks forum because it is difficult to debug such code. edit: I meant to type x = 1. sorry.
  9. my usage of htmlspecialchars is to protect you from someone trying, for example, JavaScript code in place of a name. Atleast htmlspecialchars would prevent the execution of code. You shouldn't use it on a username, email address, password etc. You will instead need to employ some sort of validation, such as regex to check names and numbers. ENT_QUOTES just converts quotations (&quot;). session_destroy: i do not know what you are creating/developing but a login/logout process will be a good idea. However, the session will be lost whenever the user closes the browser unless you are maintaining state with cookies. You could add a logout or destroy session button, which is a post to the test-sesh2.php page. Then in test-sesh2.php, detect a post with your destroy session input and implemement a session_destroy command: if isset $POST 'destroy' then session_destroy(); let us know if you need help implementing session_destroy or validating input...
  10. but it looks and functions like a login. You even refer to the poster as User in test-sesh2.php I feel compelled to mention that it is, in fact, a login of sorts. Anyway, i'm sure that this post will attract alot of helpful posts because your code is insecure among other things. I will just point out what makes it function and leave the rest to other members. here you are assigning the post values to php variables ($name and $number) instead of session variables AND you are checking if 'submit' is set but your input type submit name is actually 'register'. If you cannot remember 'register', then change it to 'submit' to avoid further complication. Thus, if you correct these errors, then your session test should work. But you shouldn't be assigning input to variables of any type without validating and filtering. Furthermore, if a User should be remembered longterm, then switch to a database for storing names and numbers and leave the session out of it. test-sesh.php <?php session_start(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['register'])) { if (!empty($_POST['name']) && !empty($_POST['number'])) { $_SESSION['name'] = htmlspecialchars($_POST['name'], ENT_QUOTES); $_SESSION['number'] = htmlspecialchars($_POST['number'], ENT_QUOTES); } } } if (isset($_SESSION['name'])) { header("Location: test-sesh-2.php"); exit; } ?> <!DOCTYPE html> <html> <head> <title>Test $_SESSION</title> </head> <body> <h1>Test $_SESSION</h1> <form method="post"> <label for="name">Name:</label> <input type="text" name="name" required><br> <label for="number">Number:</label> <input type="text" name="number" required><br> <button type="submit" name="register">Submit</button> </form> </body> </html> test-sesh2.php <?php session_start(); if (!isset($_SESSION['number'])) { header("Location: test-sesh.php"); exit; } ?> <!DOCTYPE html> <html> <head> <title>User Dashboard</title> </head> <body> <h1><?php echo $_SESSION['name']." ".$_SESSION['number']; ?></h1> </body> </html> I hope that this helps, John
  11. You have not reponded, so i want to add a second (uri method, in case you are actually trying to load a second page). My example requires an index.html page, a directory named target which contains its own index.html page. index.html at the root: <!DOCTYPE html> <html> <head> <title>CSS :target Practice</title> </head> <body> <h1>CSS :target Practice</h1> <p><a href="target/index.html#tab1">Short Description 1</a></p> <p><a href="target/index.html#tab2">Short Description 2</a></p> </body> </html> index.html in the target directory: <!DOCTYPE html> <html> <head> <title>CSS :target Practice</title> <style> ul.tabs { margin: 0px; padding: 4px; list-style-type: none; font-weight: bold; } .li { padding: 4px; border: solid 1px #ffffff; background: #ffffff; } #tab2content { display: none; } :target { border: solid 1px #009900; background: #e0e0e0; } #tab2:target { font-size: 24pt; } #tab2:target > #tab2content { display: block; } </style> </head> <body> <h1>CSS :target Practice</h1> <p>The target will be active per css (working in modern browsers: Edge/Chrome, Firefox, Opera and Safari)</p> <ul class="tabs"> <li id="tab1">!Product Enquiry</li> <li id="tab2">Product Enquiry <ul id="tab2content"><li>Hello Product seeker</li></ul></li> </ul> </body> </html> Perhaps you can let us know if you figured it out or not, John
  12. target has plenty of documentation, so you shouldn't have a problem implementing it into your code. I do not use wordpress stuff and i cannot help you with that code but here is a sample of target practice and you should be able to work it into your project regardless of the method (css or js/css etc). <!DOCTYPE html> <html> <head> <title>CSS :target Practice</title> <style> ul.tabs { margin: 0px; padding: 4px; list-style-type: none; font-weight: bold; } .li { padding: 4px; border: solid 1px #ffffff; background: #ffffff; } #tab2content { display: none; } :target { border: solid 1px #009900; background: #e0e0e0; } #tab2:target { font-size: 24pt; } #tab2:target > #tab2content { display: block; } </style> </head> <body> <h1>CSS :target Practice</h1> <p><a href="#tab1">Short Description 1</a></p> <p><a href="#tab2">Short Description 2</a></p> <p>...</p> <ul class="tabs"> <li id="tab1">!Product Enquiry</li> <li id="tab2">Product Enquiry <ul id="tab2content"><li>Hello Product seeker</li></ul></li> </ul> </body> </html> https://www.w3.org/Style/Examples/007/target.en.html https://developer.mozilla.org/de/docs/Web/CSS/:target I hope that this is helpful, John
  13. I'm not being rude but math involves numbers. <script> document.write(screen.width); </script> - 20 = not valid mathematics. you must realize that you are assigning a string to the $screenwidth variable and not a number. if you use a number then the following code will work: $screenwidth = 3072; echo $screenwidth - 20; As a string, you could echo the string where you want the script to execute within the dom. But then you cannot use the JavaScript to assign the value to a php variable. PHP is a server-side scripting language. JavaScript is a client-side scripting language. I hope that my post helps you understand what is wrong with your logic.
  14. Hi jtorral, I think that, based upon your posted four-point problem, responsive css is a better method than trying to use php to respond to media sizes. https://developer.mozilla.org/en-US/docs/Web/HTML/Responsive_images media queries can also help for images or overall css adjustments for "other functions on the page like resizing pop up boxes and so on" https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries when you veer away from JavaScript driven pop-up dialogs and move to css modal methods, the above methods will save you alot of hassle, such as trying to post to an included php file and expecting it to receive the post. Have a look at the css and try that method instead. The session should be used to maintain state, which includes databases by storing a user id for repeated querying. You could post CSS questions in the CSS Help forum: https://forums.phpfreaks.com/forum/17-css-help/ And have a second look at what Gizmola posted, John
  15. easy to forget, i guess. I'm used to working on my own projects on an up-to-date xampp installation. I just forgot that we have an outdated dump file. I suppose that it is simply a common mistake when focusing on the code. I have found several resources on the recursive cte topic: https://dev.mysql.com/doc/refman/8.4/en/with.html https://www.mysqltutorial.org/mysql-basics/mysql-recursive-cte/ https://bobcares.com/blog/mysql-recursive-cte/ https://mariadb.com/kb/en/with/ https://mariadb.com/kb/en/recursive-common-table-expressions-overview/ https://matthewdaly.co.uk/blog/2022/12/18/two-techniques-for-handling-recursive-relationships-in-mysql/ I'm going to play with this concept to gain some experience as quickly as possible, although mastering the subject will cost some time. Very fascinating. I need to upgrade my knowledge of sql in the process of this forum. Thanks for the tip, Barry. Now please spend some time relaxing. I have to log off now as my son has an appointment with a doctor. I will be back in a few hours, then i will continue upgrading my sql skills.
×
×
  • 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.