Jump to content

small insert errors...


Alidad

Recommended Posts

Hi, I"m trying to create insert images files name into the database and save images in folder, however, after i created databse connection, and excuted it... I'm getting error message said

 

 

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\ourdeaf\uploadimages\upload.php on line 76

 

That line 76 is at end of code after </html>, what went wrong!

 

 

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"  
ENCTYPE="multipart/form-data"> 
Upload:<br><br> 
<input type="file" name="image"><br><br> 
<input type="hidden" name="uploaded" value="1"> 
<input type="submit" value="Upload"> 
</form> 

<? 
}else{ 
//if the form hasn't been submitted then: 

//from here onwards, we are copying the file to the directory you made earlier, so it can then be moved  
//into the database. The image is named after the persons IP address until it gets moved into the database 

//get users IP 
$ip=$REMOTE_ADDR; 

//don't continue if an image hasn't been uploaded 
if (!empty($image)){ 

//copy the image to directory 
copy($image, "./temporary/".$ip.""); 

//open the copied image, ready to encode into text to go into the database 
$filename1 = "./temporary/".$REMOTE_ADDR; 
$fp1 = fopen($filename1, "r"); 

//record the image contents into a variable 
$contents1 = fread($fp1, filesize($filename1)); 

//close the file 
fclose($fp1); 

//encode the image into text 
$encoded = chunk_split(base64_encode($contents1));  

//insert information into the database 
mysql_query("INSERT INTO images (img,data)"."VALUES ('NULL', '$encoded')"); 

//delete the temporary file we made 
unlink($filename1); 
} 

//end 
} 
?> 

Link to comment
https://forums.phpfreaks.com/topic/212385-small-insert-errors/
Share on other sites

It has three open and closing braces.

and still get same erros message

 

did i missed any things! please help thanks.

 

 

<?php

//connect to database. Username and password need to be changed

mysql_connect("localhost", "root", "");

 

//Select database, database_name needs to be changed

mysql_select_db("images");

 

if (!$_POST['uploaded']){

//If nothing has been uploaded display the form

?>

 

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" 

ENCTYPE="multipart/form-data">

Upload:<br><br>

<input type="file" name="image"><br><br>

<input type="hidden" name="uploaded" value="1">

<input type="submit" value="Upload">

</form>

 

<?

}else{

//if the form hasn't been submitted then:

 

//from here onwards, we are copying the file to the directory you made earlier, so it can then be moved 

//into the database. The image is named after the persons IP address until it gets moved into the database

 

//get users IP

$ip=$REMOTE_ADDR;

 

//don't continue if an image hasn't been uploaded

if (!empty($image)){

 

//copy the image to directory

copy($image, "./temporary/".$ip."");

 

//open the copied image, ready to encode into text to go into the database

$filename1 = "./temporary/".$REMOTE_ADDR;

$fp1 = fopen($filename1, "r");

 

//record the image contents into a variable

$contents1 = fread($fp1, filesize($filename1));

 

//close the file

fclose($fp1);

 

//encode the image into text

$encoded = chunk_split(base64_encode($contents1)); 

 

//insert information into the database

mysql_query("INSERT INTO images (img,data)"."VALUES ('NULL', '$encoded')");

 

//delete the temporary file we made

unlink($filename1);

}

 

//end

}

?> 

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106578
Share on other sites

I see you're using short tags (<? ?>). These tags are usually disabled by default. Your server may not have short tags enabled. It is best practice to use the full PHP tags syntax (<?php ?>).

 

Also you should get into the habit of indenting your code. For example

if( )
{
     while ( whatever)
     {
           // do something
     }
}

Indenting your code makes it much more readable. Also you can easily identfiy where each code block (code between { and }) starts and and end.

 

Rather than

if( ) {
while ( whatever) {
// do something
}
}

Which makes it hard to read.

Link to comment
https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106582
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.