Alidad Posted September 2, 2010 Share Posted September 2, 2010 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/ Share on other sites More sharing options...
wildteen88 Posted September 2, 2010 Share Posted September 2, 2010 Basically that error usually means you have left of some closing braces }. Make sure your opening and closing braces matchup. Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106574 Share on other sites More sharing options...
Alidad Posted September 2, 2010 Author Share Posted September 2, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106578 Share on other sites More sharing options...
PFMaBiSmAd Posted September 2, 2010 Share Posted September 2, 2010 The error, in your case, is due to the lazy-way short open tag <? Only use full opening tags <?php to insure that your php code will always be seen as php code. Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106580 Share on other sites More sharing options...
wildteen88 Posted September 2, 2010 Share Posted September 2, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106582 Share on other sites More sharing options...
Alidad Posted September 2, 2010 Author Share Posted September 2, 2010 thanks and fixed. Quote Link to comment https://forums.phpfreaks.com/topic/212385-small-insert-errors/#findComment-1106585 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.