Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. Without the setting of $total that Barand provided you, if you had bothered to turn on error checking with: error_reporting(E_ALL); ini_set('display_errors', '1'); You would have seen this message from your starting code: Notice: Undefined variable: total in /home/albany/public_html/homejg/test.php on line 27 Which would have given you a clue to solving the problem you were having. You should turn on error checking at the top of every script your run during development.
  2. Well, to me any line that has a hanging anything is just plain wrong. Every language that I have used that depended on text-structured commands has never allowed us to leave a line 'open' at the end.
  3. So used to typing 'correctly' did not now that I could get away with a hanging comma. Something new today!
  4. Your array definition has a trailing comma. NG Why is that last function being tested? Is it your function? If so how can it be missing. If not, why are you using a function that (somehow) could be missing? You are establishing a query (?) or something from a WP_Query function. But then you make it out to be a query that doesn't look like any sql I have ever seen.
  5. The one marked as the Solution is an incomplete snippet of code that doesn't do anything.
  6. I too am a retired old man. But I like to fix my programming errors. As I asked before - how about showing us the code following your 'bad code' that 'doesn't work' so we can fix it for you. Obviously you don't know what an if statement does.
  7. If someone like you thinks that using the same if statement twice is the thing to do, then they are as confused as you are. IMO, to not want to fix what you are doing (wrongly) is a terrible way to begin your programming career. Have fun!
  8. If you take one out WHAT doesn't work? Perhaps you could show us what fails (in the proper context of course) There is absolutely no need for those duplicate statements in any code anywhere. It's what you are doing elsewhere that is failing you. Here is how I would amend it: $allowed_img = array('gif', 'png', 'jpg', 'jpeg'); ... ... ... if (isset($_POST["submit"])) { $pname = ""; if(!empty($_FILES["file"]["name"])) { $img_ext = $_FILES["file"]["name"]; $ext = pathinfo($img_ext, PATHINFO_EXTENSION); if (!in_array($ext, $allowed_img)) { echo 'Invalid file'; die(); } //file name with a random number so that similar dont get replaced $pname = rand(1000,10000) . "-" . $_FILES["file"]["name"]; $pname = str_replace(" ", "_", $pname); //temporary file name to store file $tname = $_FILES["file"]["tmp_name"]; //upload directory path $uploads_dir = 'img'; //TO move the uploaded file to specific location move_uploaded_file($tname, $uploads_dir.'/'.$pname); } } Not sure what the rest of the code is doing but this part should not be a problem. One tip - I would re-order the file name to use the name as the First part with a number appended after an UNDERSCORE, not a minus sign. And then of course I would check if the filename that you create already exists. I know you grabbed a random number but that could fail you.
  9. So why do you have this still in your code: $img_ext = $_FILES["file"]["name"]; $ext = pathinfo($img_ext, PATHINFO_EXTENSION); if (!in_array($ext, $allowed_img)) { if (!in_array($ext, $allowed_img)) { ($ext = "", $allowed_img = ""); } die(); } Not only are you doing an if test twice but the line inside that is clearly error-laden. ($ext = "", $allowed_img = ""); The above line makes no sense and I do believe it should be giving you an error. And why are you bothering to clear out the allowed extensions array? That s/b setup at the beginning of your script and left completely alone.
  10. You apparently have a problem using an if statement.... Don't now how I can fix that for you.
  11. Haven't done a file upload in awhile but why don't you simply check if there is a filename in the 'name' field and skip the upload processing when it's empty?
  12. Some notes on taking a closer look at your code: $url = isset( $_SERVER[ 'REQUEST_URI' ] ) ? basename( $_SERVER[ 'REQUEST_URI' ] ) : false; $querysl = "SELECT * from pslpages where page_url='$url'"; How can you run a query if the url is set to 'false'? And what is the point of setting your local vars to null after doing the fetch when you then immediately set them to something else depending upon whether there was a row returned from the query?
  13. As MacGyver said - the values need to be expressed as a string, not an array and not an extra parameter as you just did. Try: find_in_set(id, '77,181') And drop the quotes on the column name as you were also told.
  14. If you wrote your code to do some error checking on the success of your function calls there should be some messages for you.
  15. It "did work"? Or it "did not work"? do you have error checking enabled for your script?
  16. Do you mean: if ($row['extension'] == "mp4" || $row['extension'] == "xxx" || $row['extension'] == "aaa") { // show this file } elseif ($row['extension'] == "jpg" || $row['extension'] == "jpeg" || $row['extension'] == "txt") { // show this file instead }
  17. Why did you choose to store your data in such a strange way???
  18. May I ask - Why all the JS? Why is your approach not a simple php script wihtha simple html form that has the data fields and a Save button once the user has clicked on the Modify button?
  19. You are showing us a couple of arrays but you are not showing us how the data that is being queried is stored. Are you trying to display query results of arrays?
  20. What have you been taught in your class? Are these tables defined with varchar values for the data? Where is your attempted query statement? Where is your code that you have written to attempt to run the query and then process the resulst? We like to help those who help themselves. We are not your authors.
  21. Maybe have a hidden element in your site's form that your code has to see.
  22. Why not an html table? Here's the start of one: echo "<table border=1 style='border-collapse:collapse;'>"; while (....) { echo " <tr><td>Animal Type: </td><td>{$row['animal_type']}</td></tr> <tr><td>Animal Breed: </td><td>{$row['animal_breed']}</td></tr> <tr><td>Colour: </td><td>{$row['colour']}</td></tr> <tr><td>Owner Name: </td><td>{$row['owner_name']}</td></tr> .... "; } echo "</table>";
  23. I agree with Barand. The code you gave us only shows something if the value is not empty. Here is your code setup to do a couple of tests: echo "Test #1:<br>"; $option_second = ''; show_option($option_second); echo "Test #2:<br>"; $option_second = 'abc'; show_option($option_second); //****************** function show_option($option_second) { echo "option second is now '$option_second'<br>"; if (trim($option_second) == "") echo ""; else echo "<strong>Option:</strong> $option_second<br>"; } When you run it you will see one test result only
  24. Why not post the code that is not working and let us see what you are trying? PS - the better way of doing this is: echo "Option: " . $items['option_second']; Or: echo "Option: {$items['option_second']}"; That way you can avoid using php tags all over the place
×
×
  • 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.