-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Everything posted by cyberRobot
-
Why does my code automatically think the textbox is empty?
cyberRobot replied to Skittle's topic in PHP Coding Help
At least that means the lines processing the $_POST variables are executing. To make it so "minPrice" gets repopulated in the form, you should only need to remove the $minPrice = ""; line from the following code block: elseif (preg_match(PRICE_FILTER, $minPrice) == '0') { $error .= "<br/>Minimum price needs to be a number"; $minPrice = ""; } Of course, that won't fix the problem with the call to preg_match(). However, you should be one stop closer. -
The following link provides a seemingly better example of targeting a directory with glob(): https://www.electrictoolbox.com/php-glob-find-files/ Note that the first argument of glob() expects a pattern.
-
Did you try out glob(), as requinix suggested? I haven't used the function myself, but it appears to have a built-in sorting feature. More information, including examples, can be found here: https://www.php.net/manual/en/function.glob.php Alternatively, you could store all the file names as an array. Then using something like sort() to alphabetize them.
-
Why does my code automatically think the textbox is empty?
cyberRobot replied to Skittle's topic in PHP Coding Help
You mentioned that the script "displays the error messages". For the "minPrice" field, I assume that you see one of the error messages below, correct? If so, which one? if($minPrice == "") { $error .= "<br/>Minimum price was not specified"; } elseif (preg_match(PRICE_FILTER, $minPrice) == '0') { $error .= "<br/>Minimum price needs to be a number"; $minPrice = ""; } Are you seeing "Minimum price needs to be a number"? If so, you might want to review the manual for preg_match(). The Return Values section should be of use...especially the Warning. https://www.php.net/manual/en/function.preg-match.php#refsect1-function.preg-match-returnvalues -
Why does my code automatically think the textbox is empty?
cyberRobot replied to Skittle's topic in PHP Coding Help
Take a closer look at the following line from your form: <input type="text" name="newlist" value="<?php echo $headline ?>" /> Try outputting the corresponding variable here: $minPrice = trim($_POST["minPrice"]); var_dump($minPrice); What does it give you? -
Why does my code automatically think the textbox is empty?
cyberRobot replied to Skittle's topic in PHP Coding Help
If you look further down the script, you'll see where $_POST is being used. I'm guessing this script is being used for more than just the form submission. Note that the script that processes the form submission is looking for 'headline', which isn't in the above output. Do you know how to change the form so "newlist" is "headline"? -
Why does my code automatically think the textbox is empty?
cyberRobot replied to Skittle's topic in PHP Coding Help
After adding the lines, did you try submitting the form? $_POST doesn't get populated until your form is submitted. -
can i rssify the postings here that i post on this board
cyberRobot replied to dil_bert's topic in Miscellaneous
Why would you need something like that? What are you looking to accomplish? If you're looking for an easy way for you to see your posts, you can do that by going to your profile and clicking the "See My Activity" option. If you're looking to share everything with the world, I would suggest getting your own account through one of the many free (or paid) blogging platforms that are available. They usually have an RSS feed feature built into the solution. -
Side note: you'll want to look into getting a new secret key for reCAPTCHA before going live with your script. The key isn't exactly secret with it being posted here. More information about the key can be found here: https://developers.google.com/recaptcha/intro
-
Did you see the other part of my response? You will need to replace the smart quotes in lines like the following: $errMsg = ‘Please check the robot checkbox.’; Smart quotes will cause an HTTP 500 error. The above line should look like this $errMsg = 'Please check the robot checkbox.'; Note that the quotes are straight versus curly.
-
For future reference, it's better to post the actual code versus screenshots of the code. That way we don't need to retype things if we're interested in testing out the code. Looking at the last screenshot above, it seems like you have some smart quotes in some of the lines of code. For example, the second line has smart quotes in the $POST variable. The same goes for the next line where you are setting the value for $errMsg.
-
Also, be aware that client-side code can be tampered with. JavaScript validation can be deleted / modified without disabling JavaScript. The "required" attribute can be removed. Hidden values can be modified. Extra input tags can be added. Client-side validation should be seen more as a convenience to the user. You can let them know when something is wrong before the form is submitted. However, you should not trust that validation. Sever-side validation should be implemented to prevent tampering.
-
Here is what was provided in the original post: <input type='file' name='upload[]' multiple > You could output the $_FILES array. For example: print '<pre>' . print_r($_FILES['upload'], true) . '</pre>'; That should give you all the data sent from the fields named as "upload[]". The following page describes the elements associated with the file upload process: https://www.php.net/manual/en/features.file-upload.post-method.php The one you would be interested in is "tmp_name", which is the temporary name given by the server to the file upload. You'll need to use that to move the file to wherever you want it stored.
-
Be aware that the global variable that you are looking for is called $_FILES. Note the "S" at the end. Also, the name of your input field is "upload[]". That causes PHP to create an array for you, which is good if you're looking to upload multiple files. However, the syntax for accessing the file information will be different. For example, to access the name of the first uploaded file, you would use the following: $_FILES['upload']['name'][0] Side note: variable don't work when they are enclosed in single quoted strings. When assigning whatever value you want to $startingFolder, you need to remove the outer quotes $startingFolder = $_FILES['upload']['name'][0]; ...or you could use double quotes $startingFolder = "{$_FILES['upload']['name'][0]}";
-
No problem 😊
-
Textarea doesn't use the value attribute. Place the value between the open and close textarea tags instead. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
-
I'm guessing that you are using PDO for your database connection? Have you checked for errors? Perhaps the following will help: https://www.php.net/manual/en/pdostatement.errorinfo.php
-
Note that HTML table tags (e.g. <table>, <tr>, <td>) should be reserved for tabular data. Perhaps one of the solutions found here will help: https://css-tricks.com/fluid-width-equal-height-columns/ You could also consider using CSS grids: https://css-tricks.com/snippets/css/complete-guide-grid/ Just be aware that browser support isn't exactly ideal for CSS grids. More information can be found here: https://caniuse.com/#feat=css-grid
-
Converting custom website from PHP 5.6 to 7.2
cyberRobot replied to dc2000's topic in PHP Coding Help
In case you're not aware, the PHP manual provides a description of the changes here: https://www.php.net/manual/en/migration70.php Of course, they don't directly describe the changes from 5.6 to 7.2. You would need to go from 5.6 to 7.0, both of which will no longer be supported by DreamHost in the near future. Then you can go from 7.0 to 7.1, etc. However, it's probably much easier to set up a test environment like the others have suggested. For the test environment, you could consider setting up a sub-domain through DreamHost. Then upload the web files there to see how they function. More information about sub-domains can be found here: https://help.dreamhost.com/hc/en-us/articles/215457827-How-do-I-add-a-subdomain- Also, to delay running into this issue again, you may want to consider moving to 7.3, which is the latest version of PHP that DreamHost supports. According to the following page, that version will receive security updates until the end of 2021. https://www.php.net/supported-versions.php Then, if DreamHost follows the same pattern, 7.3 would likely be removed from their servers in late 2022. -
What version of PHP does code stored outside the root use
cyberRobot replied to cyberRobot's topic in PHP Coding Help
Ah...didn't even think of that. Yep, the version of PHP is dependent on the website that calls the helper script. Thanks! -
I have a number of PHP helper scripts that are stored outside the root directory of my websites. Those scripts may be used by one or more of my websites. Let's say I have two websites Website A uses PHP 7.0 Website B uses PHP 7.3 Will the helper scripts be potentially executed using different versions of PHP? In other words, if Website B calls a helper script using a require statement, does that helper script execute as PHP 7.3? But if Website A calls the script, it would be executed as PHP 7.0.
-
What are you looking to accomplish? Are you writing a script that processes all the information in the $_SESSION array and/or presumably the $_REQUEST array? If so, would using something like the foreach loop work for your project? That would allow you to process everything without destroying the original array.
-
Getting the error Undefined index but the column exists
cyberRobot replied to makamo66's topic in PHP Coding Help
Ah...that's what was meant by HTML variables. That makes sense. The safest bet would be to use prepared statements when working with user-supplied data in your queries. That way you're less likely to make mistakes. However, as Barand pointed out, if you're able to validate the user data in some way (and you know what you're doing), the variable containing the data could be put directly into the query. Of course, variables that might contain something that would break the query, like a quotation mark, should go through the binding process of prepared statements. That way the quotes can be escaped so the query doesn't break.