Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Unhappy Form & Upload on One Submit?

    I have a form for capturing data with empty form field validation. I also have an input which allows a user to upload an image (images uploaded into a folder, path written into a table). The problem is users can upload images WITHOUT entering any data in the form and they can submit a completed form without submitting an image. As the image is linked to the form they must be written on a single submit and not independently. Data is being written into two tables.

    Code:
    <?php
    session_start();
    include "connect.php";
    require("checkLoginSession.php");
    $message = $_GET['message'];
    error_reporting(E_ERROR);
    
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    $path = "uploads/" . $_FILES["file"]["name"];
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
    	//echo '<img src="'.$path.'" alt="" />';
    	
        if (file_exists("uploads/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "uploads/" . $_FILES["file"]["name"]);
    	  echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
          }
        }
    }
    
    $Link = mysql_connect($Host, $User, $Password);
    $user = $_SESSION['UserName'];
    $Query = "INSERT INTO $Table_3 VALUES ('0','".mysql_escape_string($user)."','{$path}')";
    if (mysql_query($Query, $Link)) { echo ("Image stored"); }else { die ("Failed to connect to database!: " .mysql_error()); };
    
    $nameErr = $intelligenceErr = $strengthErr = $speedErr = $energyErr = $fightingErr = $googleErr = $biographyErr = "";
    $name = $intelligence = $strength = $speed = $energy = $fighting = $google = $biography = "";
    
    function validate_input($data)
    {
    	$data = trim($data);
    	$data = stripslashes($data);
    	$data = htmlspecialchars($data);
    	return $data;
    }
    
    if (isset($_POST['Submit']))
    {
    	$has_errors = false;
    
    	if (empty($_POST["name"])) {
    		$has_errors = true;
    		$nameErr = "Enter a name";
    	}else{
    		$name = validate_input($_POST["name"]);
    	}
    
    	if (empty($_POST["intelligence"])) {
    		$has_errors = true;
    		$intelligenceErr = "Enter intelligence value";
    	} else {
    		$intelligence = validate_input($_POST["intelligence"]);
    	}
    
    	if (empty($_POST["strength"])) {
    		$has_errors = true;
    		$strengthErr = "Enter strength value";
    	} else {
    		$strength = validate_input($_POST["strength"]);
    	}
    
    	if (empty($_POST["speed"])) {
    		$has_errors = true;
    		$speedErr = "Enter speed value";
    	} else {
    		$speed = validate_input($_POST["speed"]);
    	}
    
    	if (empty($_POST["energy"])) {
    		$has_errors = true;
    		$energyErr = "Enter energy value";
    	} else {
    		$energy = validate_input($_POST["energy"]);
    	}
    
    	if (empty($_POST["fighting"])) {
    		$has_errors = true;
    		$fightingErr = "Enter fighting value";
    	} else {
    		$fighting = validate_input($_POST["fighting"]);
    	}
    
    	if (empty($_POST["google"])) {
    		$has_errors = true;
    		$googleErr = "Enter the googleindex";
    	} else {
    		$google = validate_input($_POST["google"]);
    	}
    	
    	if (empty($_POST["biography"])) {
    		$has_errors = true;
    		$biographyErr = "Enter a biography";
    	} else {
    		$biography = validate_input($_POST["biography"]);
    	}
    	
    	if (!$has_errors)
    	{
    		$Link = mysql_connect($Host, $User, $Password);
    		$user = $_SESSION['UserName'];
    		$Query = "INSERT INTO $Table_2 VALUES ('0','".mysql_escape_string($user)."','".mysql_escape_string($name)."','".mysql_escape_string($intelligence)."', '".mysql_escape_string($strength)."', '".mysql_escape_string($speed)."', '".mysql_escape_string($energy)."', '".mysql_escape_string($fighting)."', '".mysql_escape_string($google)."', '".mysql_escape_string($biography)."')";
    
    		if(mysql_db_query ($DBName, $Query, $Link)) {
    			$message = "Card created";
    			header("Location: comics.php?message=".urlencode($message));
    		} else {
    
    			die("Query was: $Query. Error: ".mysql_error($Link));
    		}
    	}
    }
    ?>
    
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    
    <link rel="stylesheet" href="styles/all.css" />
    <link rel="stylesheet" href="styles/forms.css" />
    <link rel="stylesheet" href="styles/slideshow1.css" />
    
    <script type="text/javascript" src="javascript/jquery-1.7.1.min.js"></script>
    
    <link href='//fonts.googleapis.com/css?family=Ubuntu:400,500' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Voltaire' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Nova+Square' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Marvel:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    
    <title>Trading Card Generator</title>
    <meta name="Description" content="Trading Card Generator" />
    <meta name="Keywords" content="Trading Card Generator" />
    
    </head>
    
    <body id="bodyform">
    
    <br style="clear:left;"/>
    
    <form action="comics.php" method ="post" enctype="multipart/form-data">
    
    <fieldset>
    <div class="legendcard">Create a Card</div>
    
    <div class="createcard">
    
    <p class="phpmessage"><?php print $message ; ?></p>
    
    <div><input id="name" class="insetcard" name="name" type="text" placeholder="Name" value="<?PHP print $name ; ?>"/>
    <p class="error"><?php echo $nameErr;?></p></div>
    
    <div><input id="intelligence" class="insetcard" name="intelligence" type="text" placeholder="Intelligence" value="<?PHP print $intelligence ; ?>"/>
    <p class="error"><?php echo $intelligenceErr;?></p></div>
    
    <div><input id="strength" class="insetcard" name="strength" type="text" placeholder="Strength" value="<?PHP print $strength ; ?>"/>
    <p class="error"><?php echo $strengthErr;?></p></div>
    
    <div><input id="speed" class="insetcard" name="speed" type="text" placeholder="Speed" value="<?PHP print $speed ; ?>"/>
    <p class="error"><?php echo $speedErr;?></p></div>
    
    <div><input id="energy" class="insetcard" name="energy" type="text" placeholder="Energy" value="<?PHP print $energy ; ?>"/>
    <p class="error"><?php echo $energyErr;?></p></div>
    
    <div><input id="fighting" class="insetcard" name="fighting" type="text" placeholder="Fighting" value="<?PHP print $fighting ; ?>"/>
    <p class="error"><?php echo $fightingErr;?></p></div>
    
    <div><input id="google" class="insetcard" name="google" type="text" placeholder="Google Index" value="<?PHP print $google ; ?>"/>
    <p class="error"><?php echo $googleErr;?></p></div>
    
    <div><textarea id="biography" name="biography" class="biography" placeholder="Enter character biography" value="<?PHP print $biography ; ?>"/></textarea>
    <p class="error"><?php echo $biographyErr;?></p></div>
    
    <input type="file" name="your-image">
    <input type="text" name="another-field">
    <input type="submit" value='submit' >
    
    </div>
    </fieldset>
    </form>
    
    </body>
    </html>
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    This is simply because you haven't done anything with the upload code to ensure that everything else has been provided. You'll need to block all required information together into the isset checks and follow the same logic used in there. I wouldn't use the $_POST['submit'] as the check either, I'd give each expected input.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    This is simply because you haven't done anything with the upload code to ensure that everything else has been provided. You'll need to block all required information together into the isset checks and follow the same logic used in there. I wouldn't use the $_POST['submit'] as the check either, I'd give each expected input.
    As the data is being written into two tables wouldn't putting all checks in once place cause problems? Do you know of any tutorials that show how to do this? All the ones I have seen do each process independently or use java for validation.
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Why would that cause problems? You can write to as many tables or databases you want to with no issues.
    My understanding of the problem is that it relies on two pieces of information, but if you only upload the image you'd end up with an orphaned set. And that behaviour is caused by not ensuring that everything you need is available before you attempt to use it. You need to verify every dependent piece of data before you write a single thing to storage. It'd be better to reject the entire submission than to create orphans which is pretty much just junk when its alone.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Why would that cause problems?
    Two queries? :

    $Link = mysql_connect($Host, $User, $Password);
    $user = $_SESSION['UserName'];
    $Query = "INSERT INTO $Table_3 VALUES ('0','".mysql_escape_string($user)."','{$path}')";
    if (mysql_query($Query, $Link)) { echo ("Image stored"); }else { die ("Failed to connect to database!: " .mysql_error()); };
    $Link = mysql_connect($Host, $User, $Password);
    $user = $_SESSION['UserName'];
    $Query = "INSERT INTO $Table_2 VALUES ('0','".mysql_escape_string($user)."','".mysql_escape_string($name)."','".mysql_escape_string($intel ligence)."', '".mysql_escape_string($strength)."', '".mysql_escape_string($speed)."', '".mysql_escape_string($energy)."', '".mysql_escape_string($fighting)."', '".mysql_escape_string($google)."', '".mysql_escape_string($biography)."')";
    You can write to as many tables or databases you want to with no issues. My understanding of the problem is that it relies on two pieces of information, but if you only upload the image you'd end up with an orphaned set. And that behaviour is caused by not ensuring that everything you need is available before you attempt to use it. You need to verify every dependent piece of data before you write a single thing to storage. It'd be better to reject the entire submission than to create orphans which is pretty much just junk when its alone.
    Yes that's what I want to do. I just don't understand how to go about it!
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I still don't see a problem with two queries. I wouldn't waste the processing time establishing two connections, but two queries are not a problem. You can only insert against one table at a time (or use a trigger to do the work for you), so in well normalized databases there are often several inserts for a single piece of data (or potentially a dump table that handles normalization division at a later offhours time).

    As for what to do, you simply do all the checks together. If the upload is not a requirement, than you simply block it aside as optional but make sure the rest of the conditions are valid first. So if its optional, put it in the !$has_errors branch. If its required, put the validation above it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    I still don't see a problem with two queries. I wouldn't waste the processing time establishing two connections, but two queries are not a problem. You can only insert against one table at a time (or use a trigger to do the work for you), so in well normalized databases there are often several inserts for a single piece of data (or potentially a dump table that handles normalization division at a later offhours time).

    As for what to do, you simply do all the checks together. If the upload is not a requirement, than you simply block it aside as optional but make sure the rest of the conditions are valid first. So if its optional, put it in the !$has_errors branch. If its required, put the validation above it.
    I've put everything together, declaring all variable at the top of the page. The code follows at the end. It validates but doesn't solve the issue. This should flag if no file is uploaded?

    Code:
      if ( ! empty($_FILES))
        {
        $message="Please upload a file";
    It doesn't.

    Code:
    <?php
    session_start();
    include "connect.php";
    $message = $_GET['message'];
    error_reporting(E_ERROR);
    
    $allowedExts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $extension = end($temp);
    $path = "uploads/" . $_FILES["file"]["name"];
    
    $nameErr = $intelligenceErr = $strengthErr = $speedErr = $energyErr = $fightingErr = $googleErr = $biographyErr = "";
    $name = $intelligence = $strength = $speed = $energy = $fighting = $google = $biography = "";
    
    function validate_input($data)
    {
    	$data = trim($data);
    	$data = stripslashes($data);
    	$data = htmlspecialchars($data);
    	return $data;
    }
    
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
      {
      if ( ! empty($_FILES))
        {
        $message="Please upload a file";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
    	//echo '<img src="'.$path.'" alt="" />';
    	
        if (file_exists("uploads/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "uploads/" . $_FILES["file"]["name"]);
    	  echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
          }
        }
    }
    if (isset($_POST['Submit']))
    {
    	$has_errors = false;
    	if (empty($_POST["name"])) {
    		$has_errors = true;
    		$nameErr = "Enter a name";
    	}else{
    		$name = validate_input($_POST["name"]);
    	}
    
    	if (empty($_POST["intelligence"])) {
    		$has_errors = true;
    		$intelligenceErr = "Enter intelligence value";
    	} else {
    		$intelligence = validate_input($_POST["intelligence"]);
    	}
    
    	if (empty($_POST["strength"])) {
    		$has_errors = true;
    		$strengthErr = "Enter strength value";
    	} else {
    		$strength = validate_input($_POST["strength"]);
    	}
    
    	if (empty($_POST["speed"])) {
    		$has_errors = true;
    		$speedErr = "Enter speed value";
    	} else {
    		$speed = validate_input($_POST["speed"]);
    	}
    
    	if (empty($_POST["energy"])) {
    		$has_errors = true;
    		$energyErr = "Enter energy value";
    	} else {
    		$energy = validate_input($_POST["energy"]);
    	}
    
    	if (empty($_POST["fighting"])) {
    		$has_errors = true;
    		$fightingErr = "Enter fighting value";
    	} else {
    		$fighting = validate_input($_POST["fighting"]);
    	}
    
    	if (empty($_POST["google"])) {
    		$has_errors = true;
    		$googleErr = "Enter the googleindex";
    	} else {
    		$google = validate_input($_POST["google"]);
    	}
    	
    	if (empty($_POST["biography"])) {
    		$has_errors = true;
    		$biographyErr = "Enter a biography";
    	} else {
    		$biography = validate_input($_POST["biography"]);
    	}
    	
    	if (!$has_errors)
    	{
    		$Link = mysql_connect($Host, $User, $Password);
    		$user = $_SESSION['UserName'];
    		$Query = "INSERT INTO $Table_2 VALUES ('0','".mysql_escape_string($user)."','".mysql_escape_string($name)."','".mysql_escape_string($intelligence)."', '".mysql_escape_string($strength)."', '".mysql_escape_string($speed)."', '".mysql_escape_string($energy)."', '".mysql_escape_string($fighting)."', '".mysql_escape_string($google)."', '".mysql_escape_string($biography)."')";
    
    		if(mysql_db_query ($DBName, $Query, $Link)) {
    			$message = "Card created";
    			header("Location: comics.php?message=".urlencode($message));
    		} else {
    
    			die("Query was: $Query. Error: ".mysql_error($Link));
    		}
    	}
    }
    
    $Link = mysql_connect($Host, $User, $Password);
    $user = $_SESSION['UserName'];
    $Query = "INSERT INTO $Table_3 VALUES ('0','".mysql_escape_string($user)."','{$path}')";
    if (mysql_query($Query, $Link)) { echo ("Image stored"); }else { die ("Failed to connect to database!: " .mysql_error()); };
    
    ?>
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #8
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Simplicity...


    if(!isset($_FILES) || empty( $_FILES)){ return error; }
    else{ process uploads; }


    This won't do anything because it's in the wrong order:
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
    {
    if ( ! empty($_FILES))
    {
    $message="Please upload a file";
    }

    else
    {...

    the error message you are wanting to send is embedded in a condition that will always return false unless an image is uploaded. Plus why would you want to ask them to upload a file if the array is not empty anyway.
    Last edited by c1lonewolf; 02-27-2014 at 09:29 PM.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by c1lonewolf View Post
    Simplicity...


    if(!isset($_FILES) || empty( $_FILES)){ return error; }
    else{ process uploads; }


    This won't do anything because it's in the wrong order:
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
    {
    if ( ! empty($_FILES))
    {
    $message="Please upload a file";
    }

    else
    {...

    the error message you are wanting to send is embedded in a condition that will always return false unless an image is uploaded. Plus why would you want to ask them to upload a file if the array is not empty anyway.
    Don't understand how to rearrange it. I'm getting Parse error: syntax error, unexpected T_BOOLEAN_OR :

    Code:
    if ( ! empty($_FILES)) {
    $message="Please upload a file";} 
    || ($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
    {
    Please list the condition with the correct syntax. I've spend all day on this.
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    That's because the code you wrote doesn't make any sense. You just threw random code inbetween other code.

    PHP Code:
    if ( ! empty($_FILES)) {
    $message="Please upload a file";} 
    This is one condition.Then you simply continue on as if you didn't do anything at all.

    PHP Code:
    || ($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/jpg")
    || (
    $_FILES["file"]["type"] == "image/png"))
    && (
    $_FILES["file"]["size"] < 2000000)
    && 
    in_array($extension$allowedExts))

    No if, no opening parens, just a random OR.

  • #11
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    That's because the code you wrote doesn't make any sense. You just threw random code inbetween other code.

    PHP Code:
    if ( ! empty($_FILES)) {
    $message="Please upload a file";} 
    This is one condition.Then you simply continue on as if you didn't do anything at all.

    PHP Code:
    || ($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/jpg")
    || (
    $_FILES["file"]["type"] == "image/png"))
    && (
    $_FILES["file"]["size"] < 2000000)
    && 
    in_array($extension$allowedExts))

    No if, no opening parens, just a random OR.
    ???? Ok now I'm more confused.

    OR ! empty($_FILES)) {$message="Please upload a file";}
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #12
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You open one condition checking if $_FILES is empty, and if it does, you assign a message.

    When that condition closes, you have nothing. You simply have an OR operator. You don't open a new condition, be it an if or an elseif. I'm nto sure how else to explain it.

  • #13
    Regular Coder
    Join Date
    Jul 2007
    Location
    England
    Posts
    132
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    You open one condition checking if $_FILES is empty, and if it does, you assign a message.

    When that condition closes, you have nothing. You simply have an OR operator. You don't open a new condition, be it an if or an elseif. I'm nto sure how else to explain it.
    Post the code!!!!! I'm only going to spend ten minutes messing about getting syntax errors.
    Please don't tell me to use mysqli - I want to work with the code I have before learning it!

  • #14
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    I'm sorry, are you getting angry at me for not fixing an error you introduced? You have a super basic syntax error; if you don't see it, I'm wondering how you got this far with your code. I'm not sure what you were trying to do at all.

    You inserted code randomly, different from what was given to you by c1lonewolf. People are helping you, and if you're going to change it and not understand what you're changing, we're simply writing code for you. Any code I give you will be the same as what c1lonewolf posted above. I'm not sure why you changed it or what you were trying to do, so I can't offer any advice on how to fix it from their starting point.

  • #15
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    if there are no file uploaded, then this condition will return false...meaning it will not run!!!
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 2000000)
    && in_array($extension, $allowedExts))
    {

    so there is no way for php to access this condition :
    if ( ! empty($_FILES)) {
    $message="Please upload a file";}

    Use what I gave you the first time and rewrite it.
    if(!isset($_FILES) || empty( $_FILES)){
    //--- no files exist so return the error message ---//
    }
    else{
    //--- files exist validate and process them ---//
    }
    It doesn't get any easier than that!
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.


  •  

    Tags for this Thread

    Posting Permissions

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