S
ScubaKing22

  • Jun 3, 2005
  • Joined May 17, 2003
  • Originally posted by JPNYC
    Come to think of it that should throw an error though.

    Nope. Perhaps a disadvantage of a language such as PHP 😉

    • Try adding a simple return; statement at the end of your function and see what happens.

      • *EDIT: Just noticed another problem. When you're making the form, you say <form action="" method ="POST">. Without any page to be submitted to, not much is going to happen.

        It looks like your problem lies in the fact that the variables you're trying to access haven't been declared. Try putting

        global $btnSubmit,$name,$email,$comment;
        

        at the top of your function. Alternatively, these are probably in the $POST array so try accessing them as such:

        if ($_POST['btnSubmit']) {
        if (($_POST['name'] == '') or ($_POST['email'] == '') or ($_POST['comment'] == ''))
        {
        

        If neither of these work, place

        error_reporting(E_ALL);
        

        at the very top of your script and see what it has to say.

        Hope this helps 😉

        • When you're generating the links for the user to click based on their search, include the parameters in the URL i.e. page_that_user_wanted.php?search_param=blah

          When you're on the search page, check to see if $_GET['search_param'] exists, and if it does, simply use that as the query.

          • Can you post the area around this line, preferably where $result is being created? Invalid result resource means that you are using the result from an invalid/non-existent query.

            • Can you post the source code? Those errors usually just mean you started outputting something before calling header(). If you need to do this, take a look at output buffering @ www.php.net

              • Try displaying the value of $_FILES['userfile']['error'], which is (obviously) the error code. Then compare it to one of the codes on this page and see what happens when a file isn't uploaded 🙂 Also, are you sure the files that aren't getting uploaded under the maximum size, which is roughly 490 KB in your case?

                P.S: Maybe take a look at Handling File Uploads for some further information.

                • Originally posted by Frederick
                  but how do I pass the image names in a loop.

                  You could try passing the filename as an item in the $_GET array.

                  On the calling page (the one with <img src> etc):

                  $images = //Array containing the image names
                  foreach($images as $image)
                  {
                      echo "<img src=\"thumb.php?file=$image\">";
                  }
                  

                  And in your create_thumb() function:

                  function create_thumb() {
                      $imgfile = $_GET['file'];	//Here you get the filename instead of from the global $filename
                      Header("Content-type: image/jpeg");
                  
                  list($width, $height) = getimagesize($imgfile);
                  $newheight = 80;
                  $newwidth = (int) (($width*$newheight)/$height);
                  
                  $thumb = imagecreatetruecolor($newwidth,$newheight);
                  $source = imagecreatefromjpeg($imgfile);
                  
                  imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
                  
                  imagejpeg($thumb);
                  }
                  
                  • I'm using Firefox and both links worked for me 🙂

                    • How bout a reliable host :p

                      (Both of those links are dead)

                      • If NULL is specified, the field is allowed to be left empty. If NOT NULL is specified, the field must be given a value. In the absence of either a NULL or NOT NULL, NULL is assumed.

                        From this article.

                        When it says 'the field is allowed to be left empty' this means when doing an INSERT query, and the opposite goes for NOT NULL.

                        Hope this helps 😉

                        • Originally posted by Frederick
                          The source below works fine if I call it from a page that just
                          outputs the code, but if I try to output this in a site where
                          output has already started prior to this code, I get garbble.

                          This is probably because once you've already started output, you can't call the header() function:

                          Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

                          If you need to have this code output something on a page that has started output, then one solution would be to do this:

                          //Assume the code in create_thumb() is placed inside thumb.php, not as a function but as 'the' code
                          <img src="thumb.php?catID=1">
                          

                          I'm almost 100% I used this sort of method before on having a dynamic signature on some forums (i.e. linked to my .php script and the image was output just fine in my signature).

                          Hope this helps 😉

                          • Sorry about that; was really tired last night when I posted that :bemused: It's not really surprising that you didn't get the error message since the query probably succeeded and thus returned a non-0 value.

                            • A few things:

                              • The initial query is returning 0 results

                              • Prefix may not have been defined but is required

                              • I threw in the mysql_error() just in case there is anything happening that may be giving you 'unseen' errors

                              <? 
                              mysql_connect($host,$user,$pass);  
                              mysql_select_db($database) or die("Could not select database"); $q = mysql_query("SELECT * FROM ".$prefix."search"); echo mysql_error(); $num = mysql_num_rows($q); echo mysql_error(); if($q > 0) { $rand = rand(1,$num); $q = mysql_query("SELECT * FROM ".$prefix."search WHERE url = '$rand' and type IN ('jpg','jpe','jpeg','png','gif')"); echo mysql_error(); $r = mysql_fetch_array($q); echo mysql_error(); $r1 = $r['url']; echo "<center><img src=\"$r1\" width=\"90\" height=\"90\"></center>"; } else { echo "No images found."; } ?>

                              If you still can't seem to get this, maybe post the exact errors; or, if this is a snippet/stripped down version of your code post the full thing 😉

                              • Should be relatively simple:

                                function selectKey($arrayToSearch,$valueToFind)
                                {
                                	$theKey = array_search($arrayToSearch,valueToFind);	//$theKey contains key of the given value if it exists in the array
                                	$hasBeenFound = false;	//Just a boolean to indicate whether or not the value was found
                                	foreach($arrayToSearch as $key=>$value)	//Go through each key & value in the array, storing the key in $key and value in $value
                                	{
                                		if($key !== $theKey)	//Check to see if the current key matches the key we're looking for
                                		{
                                			echo "<option value=\"$value\">$value</option>";	//No, doesn't match
                                		}
                                		else
                                		{
                                			echo "<option value=\"$value\" selected=\"selected\">$value</option>";	//Yes, it matches so select this option
                                			$hasBeenFound = true;
                                		}
                                	}
                                	return $hasBeenFound;
                                }
                                

                                Didn't try it out, but I don't see any glaring errors right now (although I'm pretty tired at the moment)

                                Hope this helps 😉

                                • Just use a simple stylesheet setup. Example code (albeit not very thorough):

                                  $skin = isset($_GET['skin']) ? $_GET['skin'] : "default";
                                  echo "<style type=\"text/css\" media=\"all\">@import \"".$skin.".css\";</style>";
                                  

                                  That first line checks if $_GET['skin'] exists and if it does, uses that stylesheet. Otherwise it would use 'default' stylesheet. BTW, you'd place that somewhere in the <head> area of your document.