Jump to content

Recommended Posts

Hi basicly im trying to make a page that will upload an image into a folder, but at the same time add information to a database. The image script works fine on its own, but the second i try incorporating the database bit aswell i get a unexpected T_IF Error. Any help please? Thanks.

 

The php code "upload.php"

<?php
include("connection.php")

if(isset($_POST['submit'])) { 

if(empty($_POST['title']) || empty($_POST['description']) || empty($_POST['userfile'])) {
	header("Location: admin.php?m=true"); 
	exit;
}

$title = $_POST['title'];
$description = $_POST['description'];

$query = "INSERT INTO `media` (url, title, description) VALUES ('"$upload_path . $filename"', '" . $title . "', '" . $description . "')";

	$result = mysql_query($query);

if(!$result) { 
	echo "Your query failed. " . mysql_error(); 

} else {



      $allowed_filetypes = array('.jpg','.gif','.bmp','.png');
      $max_filesize = 2097152; 
      $upload_path = 'images/';

   $filename = $_FILES['userfile']['name']; 
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); 


   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');


   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');


   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
  
  


   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.

      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed .
	}
}
?>

 

The html code. (Not from begining to end)

<td height="29">Select Image:<br />
							  (2 megabytes limit)</td>
							<td><input type="file" name="userfile" id="file"> </td>
						</tr>
						<tr>
							<td height="30">Add Title:</td>
						  <td><label>
							  <input type="text" name="title" id="title" />
							</label></td>
						</tr>
						<tr>
							<td height="141">Add Description: </td>
					  <td><label>
							  <textarea name="description" id="description" class="box" cols="50" rows="8"></textarea>
							</label></td>
						</tr>
						<tr>
							<td> </td>
							<td><label></label></td>
						</tr>
						<tr>
							<td> </td>
							<td><input type="submit" name="submit" id="submit" value="Upload Image" /></td>

 

 

The ERROR displayed is

Parse error: syntax error, unexpected T_IF in /home/zerosite/public_html/ccf/redo/pages/upload.php on line 4

 

Just incase you want to know aswell the table in the database has 4 fields and they are "id, url, title, description"

 

Thank-You in advance all help appreciated.

Link to comment
https://forums.phpfreaks.com/topic/122628-solved-t_if-error-help-for-image-upload/
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.