Click to See Complete Forum and Search --> : saving data in the database


franknu
01-23-2007, 01:53 PM
i want to upload some data along with two pictures maybe more in the future,

for some reason it is not uploading anything,



define ("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']));
{

$fullpath1 = $uploaddir . $uploadfile1;
$today=date("m-d-y");

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

$result= move_uploaded_file($_FILES['Picture1']['tmp_name'], UPLOADDIR .$filename1);
}
if($result==1)
{

echo"picture one uploaded";
}

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

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

print_r($_FILES);


if ($result==1)

{

echo"Picture2 uploaded";

}

if (move_uploaded_file($_FILES['Picture2']['tmp_name']. UPLOADDIR .$fullpath1) && ($_FILES['Picture1']['tmp_name']. UPLOADDIR .$fullpath2))

{


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

Values('$BusinessName','$Slogan','$Business_Address','$Tel','$Website','$Email','$Fax','$type','$mak e','$Categories','$Keyword',
'$fullpath1','$Headline','$Slogan2','$Description1',
'$Description2','$Description3','$fullpath2','$fullpath1','$User_Name','$Password')";
mysql_query($sql)or die(mysql_error());
}

}




?>


here is my error message: Warning: Wrong parameter count for move_uploaded_file()

NightShift58
01-23-2007, 02:41 PM
There was at least one problem with a semicolon that was preventing an IF from doing its job and very probably causing a ripple effect through the rest of the script...

Also, I don't know where all these variables are coming from. I think they're probably reaching the page via POST. If so, you have to initialize them before you use them and they should also be escaped.<?php
print "<pre>";
print_r($_FILES);
print "</pre>";

define ("UPLOADDIR", "/home/townsfin/public_html/business_images/");

// All POST vars to vars..
$BusinessName = mysql_real_escape_string($_POST['BusinessName']);
$Slogan = mysql_real_escape_string($_POST['Slogan']);
//etc...

IF ($_FILES['Picture1']) :

$moved1 = false;
$moved2 = false;

IF (is_uploaded_file($_FILES['Picture1']['tmp_name'])) :
$uploadfile1 = $_FILES['Picture1']['name'];
$fullpath1 = UPLOADDIR . $uploadfile1;
$filename1 = $_POST['name']. "1";
IF (move_uploaded_file($_FILES['Picture1']['tmp_name'], UPLOADDIR .$filename1)) :
$moved1 = true;
echo "picture $fullpath1 uploaded";
ENDIF;
ENDIF;

IF (is_uploaded_file($_FILES['Picture2']['tmp_name'])) :
$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2 = UPLOADDIR . $uploadfile2;
$filename2=$_POST['name']. "2";
IF (move_uploaded_file($_FILES['Picture2']['tmp_name'], UPLOADDIR .$filename2)) :
$moved2 = true;
echo "picture $fullpath2 uploaded";
ENDIF;
ENDIF;

IF ($moved1 and $moved2) :
$sql = "INSERT INTO `business_info` ";
$sql . = "SET `BusinessName`= '$BusinessName', ";
$sql . = " `Slogan`= '$Slogan', ";
$sql . = " `Business_Address`= '$Business_Address', ";
$sql . = " `Tel`= '$Tel', ";
$sql . = " `Website`= '$Website', ";
$sql . = " `Email`= '$Email', ";
$sql . = " `Fax`= '$Fax', ";
$sql . = " `type`= '$type', ";
$sql . = " `make`= '$make', ";
$sql . = " `Categories`= '$Categories', ";
$sql . = " `Keyword`= '$Keyword', ";
$sql . = " `Picture1`= '$fullpath1', ";
$sql . = " `Headline`= '$Headline', ";
$sql . = " `Slogan2`= '$Slogan2', ";
$sql . = " `Description1`= '$Description1', ";
$sql . = " `Description2`= '$Description2', ";
$sql . = " `Description3`= '$Description3', ";
$sql . = " `Picture2`= '$fullpath2', ";
$sql . = " `Picture3`= '$fullpath1', ";
$sql . = " `User_Name`= '$User_Name', ";
$sql . = " `Password` = '$Password' ";
mysql_query($sql)or die("SQL Error: $sql<br>" . mysql_error());
ENDIF;
ENDIF;
?>The way your script was setup, it required the user to upload 2 images or else nothing would happen. Is that correct?

franknu
01-23-2007, 03:22 PM
i am getting this error:

Parse error: syntax error, unexpected '=' in

$sql . = "SET `BusinessName`= '$BusinessName', ";

NightShift58
01-23-2007, 03:27 PM
Please remove the spaces between . and = It should be .= (together)

franknu
01-23-2007, 03:28 PM
i am getting this error:

Parse error: syntax error, unexpected '=' in

$sql . = "SET `BusinessName`= '$BusinessName', ";

NightShift58
01-23-2007, 03:37 PM
Fixed...<?php
print "<pre>";
print_r($_FILES);
print "</pre>";

define ("UPLOADDIR", "/home/townsfin/public_html/business_images/");

// All POST vars to vars..
$BusinessName = mysql_real_escape_string($_POST['BusinessName']);
$Slogan = mysql_real_escape_string($_POST['Slogan']);
//etc...

$moved1 = false;
$moved2 = false;

IF (is_uploaded_file($_FILES['Picture1']['tmp_name'])) :
$uploadfile1 = $_FILES['Picture1']['name'];
$fullpath1 = UPLOADDIR . $uploadfile1;
$filename1 = $_POST['name']. "1";
IF (move_uploaded_file($_FILES['Picture1']['tmp_name'], UPLOADDIR .$filename1)) :
$moved1 = true;
echo "picture $fullpath1 uploaded";
ENDIF;
ENDIF;

IF (is_uploaded_file($_FILES['Picture2']['tmp_name'])) :
$uploadfile2= $_FILES['Picture2']['name'];
$fullpath2 = UPLOADDIR . $uploadfile2;
$filename2=$_POST['name']. "2";
IF (move_uploaded_file($_FILES['Picture2']['tmp_name'], UPLOADDIR .$filename2)) :
$moved2 = true;
echo "picture $fullpath2 uploaded";
ENDIF;
ENDIF;

IF ($moved1 and $moved2) :
$sql = "INSERT INTO `business_info` ";
$sql .= "SET `BusinessName`= '$BusinessName', ";
$sql .= " `Slogan`= '$Slogan', ";
$sql .= " `Business_Address`= '$Business_Address', ";
$sql .= " `Tel`= '$Tel', ";
$sql .= " `Website`= '$Website', ";
$sql .= " `Email`= '$Email', ";
$sql .= " `Fax`= '$Fax', ";
$sql .= " `type`= '$type', ";
$sql .= " `make`= '$make', ";
$sql .= " `Categories`= '$Categories', ";
$sql .= " `Keyword`= '$Keyword', ";
$sql .= " `Picture1`= '$fullpath1', ";
$sql .= " `Headline`= '$Headline', ";
$sql .= " `Slogan2`= '$Slogan2', ";
$sql .= " `Description1`= '$Description1', ";
$sql .= " `Description2`= '$Description2', ";
$sql .= " `Description3`= '$Description3', ";
$sql .= " `Picture2`= '$fullpath2', ";
$sql .= " `Picture3`= '$fullpath1', ";
$sql .= " `User_Name`= '$User_Name', ";
$sql .= " `Password` = '$Password' ";
mysql_query($sql)or die("SQL Error: $sql<br>" . mysql_error());
ENDIF;
?>

franknu
01-23-2007, 04:00 PM
thank u so much i was working on this for days

NightShift58
01-23-2007, 04:03 PM
You're welcome!