Jump to content

uploading multiple files in the database


franknu

Recommended Posts

i have this code to upload multiple files  the error that i am getting is

[code=php:0]

Parse error: syntax error, unexpected '=' in /home/townsfin/public_html/html_forms/insert_data.php on line 105
[/code]

probably i have other errors but i need to go through this one first

[code=php:0]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Hello!</title>
</head>

<body>

<?


$host = "localhost";
$username = "townsfin_localho";
$password = "abc123";
$database = "townsfin_contacts";

$db = mysql_connect($host, $username, $password);
mysql_select_db($database);



  // Business Owner

  $First_Name = addslashes($_POST['First_Name']);
  $Last_Name= addslashes($_POST['Last_Name']);
  $Owner_Address = addslashes($_POST['Owner_Address']);
  $State= addslashes($_POST['State']);
  $City= addslashes($_POST['City']);
  $Zip= addslashes($_POST['Zip']);
  $Tel= addslashes($_POST['Tel']);
  $Email= addslashes($_POST['Email']);
  $Position=addslashes($_POST['Position']);
  $Comments=addslashes($_POST['Comments']);


// Business Info

$BusinessName = addslashes ($_POST['BusinessName']);
$Slogan = addslashes($_POST['Slogan']);
$Business_Address = addslashes($_POST['Business_Address']);
$Tel = addslashes($_POST['Tel']);
$Website = addslashes($_POST['Website']);
$Email = addslashes($_POST['Email']);
$Member_Status = addslashes($_POST['Member_Status']);
$Fax =addslashes($_POST['Fax']);
$type = addslashes($_POST['type']);
$make = addslashes($_POST['make']);

// webpage info

$Categories = addslashes($_POST['Categories']);
$Keyword = addslashes ($_POST['Keyword']);
$Picture1 = addslashes (isset ($_POST['Picture1']));
$Headline = addslashes ($_POST['Headline']);
$Slogan2 = addslashes ($_POST['Slogan2']);
$Description1 = addslashes ($_POST['Description1']);
$Description2 = addslashes ($_POST['Description2']);
$Description3= addslashes ($_POST['Description3']);
$Contact2 = addslashes ($_POST['Contact2']);
$Picture2 = addslashes (isset($_POST['Picture2']));
$Picture3 = addslashes (isset($_POST['Picture3']));

$User_Name = addslashes ($_POST['User_Name']);
$Password = addslashes ($_POST['Password']);


if(!$db)

{
echo " Error: could not connect to database.";

exit;
  }


                  //business owner
$sql="INSERT INTO `business_owner`(`First_Name`,`Last_Name`,`Owner_Address`,`State`,`City`, `Zip`,`Tel`, `Email`,`Comments`,`Position`)
VALUES ('".$First_Name."','".$Last_Name."','".$Owner_Address."','".$State."','".$City."','".$Zip."','".$Tel."','".$Email."','".$Comments."','".$Position."')";

$result = mysql_query($sql);
echo mysql_error();

if($result)
        {
echo mysql_affected_rows()." .Business Owner information Inserted. <br>";
          }


    //Business Info


$uploaddir = '/home/townsfin/public_html/business_images/';
$uploadfile1 = $_FILES['Picture1']['name'];

if(isset ($_FILES['picture1'])){

If(is_uploaded_file($_FILES['Picture1']['tmp_name'])&&
is_uploaded_file($_FILES['Picture2']['tmp_name']));

$fullpath = $uploaddir . $uploadfile1;

filename1=$_POST['name']. "1";
103 $result= move_uploaded_file($_FILES['picture1']['tmp_name'], $fullpath."/". "$filename1");
104
105. if($result==1)
106
    $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath','$fullpath','$User_Name','$Password')";

$result = mysql_query($sql);

echo "file uploaded";

$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2=$uploaddir . $uploadfile2

filename2= $_POST['name']. "2";
$result = move_uploaded_file($_FILES['picture2]['tmp_name'], $fullpath. "/" "$filename2");

  if ($result==1)

  $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath1','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath2','$fullpath1','$User_Name','$Password')";

$result = mysql_query($sql);



      }
      }
}


?>





</body>

</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/34431-uploading-multiple-files-in-the-database/
Share on other sites

It's the line above that...

Try changing this:

[code]filename1=$_POST['name']. "1";[/code]

To this:

[code]$filename1=$_POST['name']. "1";[/code]

Also further down you're missing a semi-colon on the end of this line:

[code]$fullpath2=$uploaddir . $uploadfile2[/code]

and a $ sign at the beginning of this line:

[code]filename2= $_POST['name']. "2";[/code]



Regards
Huggie
this is the error that i am getting now, and i am gettin it on the next line

Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/townsfin/public_html/html_forms/insert_data.php on line 126


[code=php:0]

$uploaddir = '/home/townsfin/public_html/business_images/';
$uploadfile1 = $_FILES['Picture1']['name'];

if(isset ($_FILES['Picture1'])){

If(is_uploaded_file($_FILES['Picture1']['tmp_name'])&&
is_uploaded_file($_FILES['Picture2']['tmp_name']));

$fullpath = $uploaddir . $uploadfile1;

$filename1=$_POST['name']. "1";
$result= move_uploaded_file($_FILES['picture1']['tmp_name'],  $fullpath."/". "$filename1");

if($result==1)

    $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath','$fullpath','$User_Name','$Password')";

$result = mysql_query($sql);

echo "file uploaded";

$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2=$uploaddir . $uploadfile2;

$filename2= $_POST['name']. "2";
$result = move_uploaded_file($_FILES['picture2]['tmp_name'], $fullpath. "/" "$filename2");

  if ($result==1)

  $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath1','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath2','$fullpath1','$User_Name','$Password')";

$result = mysql_query($sql);



      }
      }
}


[/code]
how about an opening curly brace after the IF statement????

this would prevent the origonal error because it would think that the $sql="BLAH" would be on the same line as the IF statement therefore unexpected = on line 105

or am i barking up the wrong tree?
ok  i made more changes

the problem now is that it says that it has upload the files but when i look into the database there is nothing there

here is my code

[code=php:0]


$uploaddir = '/home/townsfin/public_html/business_images/';
$uploadfile1 = $_FILES['Picture1']['name'];

if(isset ($_FILES['Picture1']))
{

If (is_uploaded_file($_FILES['Picture1']['tmp_name'])&&
is_uploaded_file($_FILES['Picture2']['tmp_name']));

$fullpath = $uploaddir . $uploadfile1;

$filename1=$_POST['name']. "1";
$result= move_uploaded_file($_FILES['picture1']['tmp_name'],  $fullpath."/". "$filename1");

if($result==1)

    $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath','$fullpath','$User_Name','$Password')";

$result = mysql_query($sql);

echo "picture1 front of business uploaded";

$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2=$uploaddir . $uploadfile2;

$filename2= $_POST['name']. "2";
$result = move_uploaded_file($_FILES['picture2']['tmp_name'], $fullpath. "$filename2");

  if ($result==1)

  $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath1','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath2','$fullpath1','$User_Name','$Password')";

$result = mysql_query($sql);

echo " <br> Picture2  uploaded";



     
     
}


?>
[/code]
[code=php:0]
$uploaddir = '/home/townsfin/public_html/business_images/';
$uploadfile1 = $_FILES['Picture1']['name'];

if(isset ($_FILES['Picture1']))
{

If (is_uploaded_file($_FILES['Picture1']['tmp_name'])&&
is_uploaded_file($_FILES['Picture2']['tmp_name']));

$fullpath = $uploaddir . $uploadfile1;

$filename1=$_POST['name']. "1";
$result= move_uploaded_file($_FILES['picture1']['tmp_name'],  $fullpath."/". "$filename1");

if($result==1)
{

    $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath','$fullpath','$User_Name','$Password')";


$result = mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());

echo "picture1 front of business uploaded";

}

$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2=$uploaddir . $uploadfile2;

$filename2= $_POST['name']. "2";
$result = move_uploaded_file($_FILES['picture2']['tmp_name'], $fullpath. "$filename2");

  if ($result==1)

  {

  $sql="INSERT INTO `business_info`(`BusinessName`,`Slogan`,`Business_Address`,`Tel`,`Website`,`Email`,
`Fax`,`type`,`make`,`Categories`,`Keyword`,`Picture1`,`Headline`,`Slogan2`,`Description1`,`Description2`,`Description3`,
`Picture2`,`Picture3`,`User_Name`,`Password`)

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$make','$Categories','$Keyword',
'$fullpath1','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath2','$fullpath1','$User_Name','$Password')";


$result = mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());

echo " <br> Picture2  uploaded";

}

     
     
}


?>
[/code]

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.