Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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