SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two If's in a statement

    I got this code, but i keep getting the error error uploading image,but if i take the If statements away it works.

    i have 2 if codes in 1 statement is this the correct way?

    Code:
    <?php
    include "../../conf/db_connect.php";
    $name = $_POST['name'];
    $type = $_POST['type'];
    $cat = $_POST['cat'];
    $limit = $_POST['limit'];
    $minlocation_len = 3; //location minimum length
    $target_path = "../../images/locations/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    
          if(strlen($name) < $minlocation_len)
          {
          ?>
               <script type="text/javascript">
    	          alert ("Location name must be atleased 3 characters!")
    
    
    
    	        </script>
          <meta http-equiv="REFRESH" content="0;url=../newlocation.php">
          <?php
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    
          $request = "INSERT INTO `room` ( `RoomID` , `RoomName` , `RoomType` , `RoomImage` , `RoomLimit` , `RoomCat`)
    
    	  VALUES (
    
    	  '' , '$name' , '$type' , '$siteurl/images/locations/$name.png' , '$limit' , '$cat');";
    
    	  // execute the query
    	  $result = mysql_query($request) or die(mysql_error());
        ?>
             <script type="text/javascript">
    	        alert ("Location added!")
    
    
    
    	      </script>
          <meta http-equiv="REFRESH" content="0;url=../locations.php">
          <?php
    }
    }
    else{
    ?>
         <script type="text/javascript">
            alert ("Uploading location image failed!")
    
    
    
          </script>
          <meta http-equiv="REFRESH" content="0;url=../newlocation.php">
          <?php
    }
    
    ?>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What your code says is:

    if the name is less than 3 characters, then print a meta refresh AND UPLOAD THE IMAGE

    if the name is not less than 3 characters, write "uploading image failed" and refresh

    I think you want to rearrange that a bit You want the "else" part of your first condition (that the name is long enough) to be where your image upload happens.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok hmm works, also when i upload a image can i change the name of the image through php?
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, just change the second argument to move_uploaded_file (what you're setting to $target_path).

  5. #5
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm i dont understand, if i upload the file untitled.jpg can i change the name when uploading from untitled.jpg to mike.jpg
    Animated Chatrooms - www.121chatrooms.net

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Change this:
    PHP Code:
    $target_path $target_path basename$_FILES['uploadedfile']['name']); 
    To this:
    PHP Code:
    $target_path $target_path "mike.jpg"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •