Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Posts 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. 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.  

  3. 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.

  4. 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.

  5. 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.

  6. 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?

     

  7. 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
    	}

     

  8. 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.

    • Thanks 1
  9. 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>";

     

  10. 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

×
×
  • 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.