Jump to content

Total PHP Failure


darkstoine3

Recommended Posts

My code is a total failure. Any ideas?

 

<?php
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"] ["size"] < 4000000))
  {
  echo "Return Code: " . $_FILES["file"]["error"] . "<br />That means your picture is not right somehow...<br />";
  }
else
  {
  $i=1;
  while($i<=5000)
    {
    if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]]))
      {
      $i++;
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]);
      $i=5000;
      }
    }
  }
else
  {
  echo "Invalid file... Only 4MB and jpeg/gifs allowed.";
  }

$con = mysql_connect(
  'localhost',
  'root',
  'password')

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("submition", $con)

$sql = "INSERT INTO 'submition' ('fname','lname','address1','address2','city','stat_prov_reg','postal_zip','country','email','newsletter') VALUES ('"$POST['element_1_1']."' , '"$POST['element_1_2']."' , '"$POST['element_2_1']."' , '"$POST['element_2_2']."' , '"$POST['element_2_3']."' , '"$POST['element_2_4']."' , '"$POST['element_2_5']."' , '"$POST['element_2_6']."' , '"$POST['element_3']."' , '"$POST['element_7']."')";

mysql_query($sql) or die('Bad Query');

mysql_close($con);
?>
<div align="center">
- <a href="http://apps.facebook.com/fourxfourexperience/'>Go Back</a> -
</div>

Link to comment
https://forums.phpfreaks.com/topic/217143-total-php-failure/
Share on other sites

..and your indentation. Change it. Also, you should construct variables where necessary. Like this:

 

  $i=1;
  while($i<=5000)
    {
    if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]]))
      {
      $i++;
      }
    else
      {
        .....
       }

 

Should be far cleaner and simpler:

 

$i=1;
while($i <= 5000){

$filename = "./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"];

  if(file_exists($filename)){
    $i++
  }else{
    .....
  }

}

 

note: not checked for syntax issues.

 

You should use the above structure because your code will be highly unmaintainable as you develop it and it becomes more complex.

Link to comment
https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1129634
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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