echocpt Posted September 3, 2008 Share Posted September 3, 2008 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 More sharing options...
php_dave Posted September 3, 2008 Share Posted September 3, 2008 Your missing a ; on your include statement include ("connection.php"); Link to comment https://forums.phpfreaks.com/topic/122628-solved-t_if-error-help-for-image-upload/#findComment-633184 Share on other sites More sharing options...
echocpt Posted September 4, 2008 Author Share Posted September 4, 2008 lol thanks, its allways the simple things u never spot. Link to comment https://forums.phpfreaks.com/topic/122628-solved-t_if-error-help-for-image-upload/#findComment-633814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.