Jump to content

StevenOliver

Members
  • Posts

    237
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by StevenOliver

  1. no no no..... all the values can be the same (they can all say value="Click Me").... it's the NAME which is what PHP looks for! And those are hidden from view from the browser. (Anyone can see it in browser source though, no biggy). The web visitor just sees a button with "click me" on it. But your php code will see what you named each button. Visitors will see what you put for the "value" <input type="submit" name="movies" value="click me"> <input type="submit" name="advanced_users" value="click me"> <input type="submit" name="button_two" value="click me">
  2. LOL a perfect example of why more than one form is a pain. Seeing just 10 lines of code with 3 forms already giving me a headache :-)
  3. I'll assume your pages are a bit more complex. However, it sounds like your page would go something like this, in pseudocode: <form name="my_only_form" method="post" action="php_processing_page.php"> :: Advanced Users, Click Here :: <input type="submit" name="advanced" value="Click Me if Your Advanced"> :: Beginners Click Here :: <input type="submit" name="beginner" value="Click Here Learn More"> :: Show Video :: <input type="submit" name="movies" value="Click For Movies"> Then, on your php_processing_page.php, your code will decide what you want your visitors to see or do. For example: <?php if(isset($_POST["movies"])) { echo 'Here is your movie:'; echo '<video width="320" height="260" controls> <source src="movie.mp4" type="video/mp4"> </video>'; } You can do a mockup, then go through and fortify everything, sanitize, make sure referrer is your own page, etc.
  4. I have rather simple PHP pages. Here is the stuff that's on my pages: echo '<form name="myform" method="post">'; echo 'Some text here, blah blah'; echo '<input type="submit" name="buttonOne">'; echo 'more stuff here'; echo '<input type="submit" name="buttonTwo">'; echo '</form>'; in my PHP processing on top of the page: if(isset($_POST["buttonTwo"])) { // do what buttonTwo is supposed to do // for example, go to different page: header('Location: http://www.example.com/'); exit; } if(isset($_POST["buttonOne"])) { // do the stuff that buttonOne is supposed to do } As long as each button has a different name="somethingDifferent" then your PHP processing page (wherever you submit your form to) will do whatever you want. Note that ALL "hidden inputs" in a form get submitted <input type="hidden" name="unique_name" value="likes_boats"> each time a button is clicked.... but your PHP processing page can decide what info it is going to use.
  5. Having more than one form on a page is a nightmare for me. If I could do all my websites over again, I would have ONE form, name it "form1" and be done with it. It might seem fine and dandy to have 2, 3 or 5 forms.... but wait 'till you go on vacation and come back, and then you cannot remember/figure out what form does what, what the forms are named, etc., where one form ends and another begins, etc. Right now, your website has x number of lines of code. After a few years, you will have 1000's of lines of code. Having one form instead of several would seem like the best thing to do.
  6. jodunno, thank you! I'm going to try that now. I was just going to implement my horrible javascript hack when I saw your code. I'll try your code now. Thank you!!
  7. I FIGURED IT OUT! JAVASCRIPT! Yep, Javascript. Force the text values of ALL the Price Field to change before POST. I'll give all the <input> rows the id's of the sku numbers, and then use the if (e.keyCode == 13)", to change all the price values of the matching sku rows to my desired price right before POST. See? Take a big mess, simply add slop, and voila! All fixed. Real good. There! Done! Next Project! 😷
  8. jodunno, you're right. Subsequent duplicate occurences of the <input name="dupe" value="dupe"> will "override" whatever I change in the first occurence. In simple terms, "only change the last of the duplicates..... don't change any of the first duplicates." I wish I was smart enough to understand mac_gyver's array suggestion.... I think that's where the answer lies. I can't wrap my head around arrays.
  9. .... now I have a dozen things to learn... You have "$post = [] Is that the same as declaring it as an array like this: $post = array(); I see this alot: if($_SERVER['REQUEST_METHOD'] == 'POST') { Is that always necessary? Doesn't the mere "if(isset($_POST["something"])) do the trick? "Modern code" seems to have an excess of "if there's no problem here, check here for a problem" if(empty($errors) How do you know when to say if(empty($errors)) vs if($errors == NULL) PDO...... (saving that for later this summer. I'm just now converting (and figuring out how to convert) all my 90's mySQL to "oo" style mySQLi) So upon cursory exam of your the html side of your code, it doesn't look like it provides for listing each duplicated sku discreetly..... it probably does, but I don't see it. I will have to run the code, and see which line of code does this. Probably the foreach($post['sku'] as $sku=>$price) part. I would probably stick a $post['sku'] = $userSubmittedPrice in there.... Okay thank you again! I'm going to run the code....
  10. 😀 mac_gyver, I indeed read your post (when you made your last post, I had 10 browser windows open with form array examples). I've been experimenting this whole time.
  11. mac_gyver, thank you! It didn't occur to me to use arrays, I like that idea! I'm going to try your code now.
  12. @jodunno, thank you. But if there are duplicates, only changing the last one will update all the sku's prices. Here is the result of a mySQL foreach loop. The name and price values are dynamically generated ("select name,price from my_mysql_table...."😞 <input type="text" name="A3829'" value="5.00"> <BR> <input type="text" name="A1444'" value="12.00"> <BR> // <-- manually changing this has no effect <input type="text" name="A1444'" value="12.00"> <BR> // <-- manually changing this one correctly updates both duplicates <input type="text" name="A9035'" value="3.00"> <BR> So if I change the first $12.00 line to $5.00, the second duplicate line will revert my change when the form is posted. It only works if I change the final $12.00 line (then all those same sku numbers will be updated to my desired price). PHP pseudocode would be: If user updates value for a specific SKU { update all items with same SKU to updated price; }
  13. No, just temporarily changing the prices. An example scenario: I tell a customer the next time they come in I'll sell them a hammer at half price. The customer brings a screwdriver, 3 hammers, a shovel, and a hoe to the counter. I then type in the SKU numbers and get this result: sku# 23455.....$5.00 sku# 11111.....$10.00 sku# 11111.....$10.00 sku# 11111.....$10.00 sku# 875..........$9.00 sku# 301..........$7.00 I remember he gets hammers at half price.... so I manually change the "$10.00" to the "$5.00" before I print the customer's receipt, and then close the browser/delete all temporary variable for the next customer....etc.
  14. mac_gyver, I manually input a series of sku's into my form to retrieve default prices from mySQL database, using a foreach loop. Doing so will result in a list of a dozen or so sku numbers with prices, e.g. sku# 23455.....$5.00 sku# 11111.....$10.00 sku# 11111.....$10.00 sku# 875..........$4.00 While reviewing the displayed result in my browser, I may wish to manually change sku# 11111 to display $5.00 instead of the default $10.00. And, I'd like to be able to do that by clicking on the "$10.00" and simply typing in $5.00, then hit "Submit" and voila! Desired Result: sku# 23455.....$5.00 sku# 11111.....$5.00 sku# 11111.....$5.00 sku# 875..........$4.00 p.s. found a new problem..... you can't echo a number, so I have to append a letter prefix "A" to each of the "name" values in my original post: echo '<input type="text" name="A"'.$sku.'" value="'.$price.'">'; .... and now the code is really ugly.... there's got to be a modern way of doing this.
  15. I've been trying for days to get this simple 1990's code to work. It won't work. Now, I don't even want to get it to work, because it's crappy ugly 1990's code... Is there an elegant way to accomplish this? (I just want to be able to manually override the default catalog prices as needed.) <?php //default catalog prices: $sku = "123456"; $price = "5.99"; if(isset($_POST[$sku])) { // if form submitted, and if( ${$_POST[$sku]} != $price) { //...and I manually changed price $price = ${$_POST[$sku]}; //...then change price to what I input } } echo '<form name="form1" method="post" action="Crappy1990sCodePage.php">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">'; echo '<input type="text" name="'.$sku.'" value="'.$price.'">';// (same sku may be listed twice) echo '<input type="submit" class="no_class_its_the_90s_remember">' echo '</form>'; ?> Thank you 😀
  16. I bookmarked this, too. I know nothing about PDO, I'm intent on learning it! Thank you!!
  17. maxxd, that's a nice way. I like how there is no overlap. Another way, (depending how the mysql table is set up), might be: select * from my_table where dateInfo >= 2020-01-01 and dateInfo <= '2020-07-19';
  18. Okay good, I just now tried that. Now I'm seeing every error. Thank you! Also, I never thought of having output_buffering off -- I am glad you pointed that out. Maybe that's the issue I've had the most in the past. One thing I found -- sometimes when I have error reporting turned on with all errors, I sometimes get lazy in coding. like, I'll type anything and wait for the error.... type something else and watch the error 😀 ... But when I have error reporting OFF, it makes me concentrate more on typing correctly because nothing is more annoying than the "blank page".
  19. I actually thought 2020 was the "Hi Friends" guy that got banned about a year ago. He wouldn't even wait a full day before asking the same questions, like he never read the answers. At least I READ the answers.... My problem is I get sidetracked.... For example, a few days ago I was trying to learn how only have one redirect no matter what... and now I have 30 browser windows open trying to learn regex..... and in doing so, I'm learning preg_match, where the answer is contained in an array, and now I realize my Array knowledge is ZERO..... I really wish I could start at the beginning, and learn PHP from the ground up and MASTER something before I die....
  20. mac_gyver, what is the best code to put into php.ini to show all errors? When I'm coding, I put error_reporting(E_ALL), ini_set("display_errors", and include("file_with_errors.php"); on top of each page, but at least half the time I'll get a completely blank page because I did something stupid like echoed with a colon instead of semicolon. If there was something I could put in my php.ini file to show even THOSE types of errors, I'll buy you a beer. p.s. I wish there was somebody in my dumb little town who could actually teach php to me from the ground up. I would sign up in a heartbeat. I can read 2020's code, and I can read my own code... but when I see code that Barand (or you) spits out, OMG, I cannot make heads nor tales of it. LIke that double underscore __blah__ stuff. Or the "try" "do" stuff....
  21. I have no clue. Google will have to help you there.
  22. One day I decided to check out my own Shared Hosting website, typed in the URL, and instead of a page appearing, a "file" downloaded to my computer desktop. Turns out that the hosting provider did a mass "upgrade" which broke the custom code in my .htaccess file, which in turn caused all my PHP pages to be considered as "files," which all got downloaded to anyone who visited any of my pages. I learned 2 lessons: a.) Don't have poorly written .htaccess code which can be 'broken' b.) Don't have any sensitive data (like your mySQL "conn.php" username password, etc.) in any public directories. Either put them up one level, or, like Barand said, define them in your php.ini so that later, even you won't be able to find them 😀
  23. This is an easy question! Line two has the word "ALL" in it! 😀
  24. @2020, good, you have PHP error reporting turned on.... but where is your mySQL error reporting? Just yesterday there is a whole important thread here on this (I think if you implement it, you'll find what's going wrong): p.s. Okay, let's do a PDO race. But I should be given a head start, considering my old age 😀
  25. Requinix, thank you! All your answers make sense.... what happens to me is I set out to write a block of code, but then I go off on two tangents. Then from each of those two tangents, I go onto two more tangents, etc., By the end of the day, I have 30 forked tangents, with 30 browser windows open with tutorials on everything 😀 Kicken, thank you! I have your suggested documentation open in another browser window right now. I'm going to read it now. Regarding simple things like making sure HTTPS is on or off, well, I do have the brain power, but I don't have the lexicon/context of years of PHP learning to know which is the best way to do something. For example: a.) RewriteCond %{HTTPS} off b.) RewriteCond %{ENV:HTTPS} !on c.) RewriteCond %{SERVER_PORT} 80 But anyway, I'm gonna read me some Apache Docs! 😀
×
×
  • 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.