davinci Posted March 9, 2006 Share Posted March 9, 2006 Trying to mix and match pieces of code in order to get a way to post news to my site but including uploading a thumbnail. Here's what I came up with. However I get an error: Parse error: parse error, unexpected $ in /xxx/public_html/test/addplug.php on line 160 but don't know why considering I don't have a "$" on that line! Can someone help?[code]<?php// include the database configuration and// open connection to databaseinclude 'library/config.php';include 'library/opendb.php';$uploadDir = 'media/thumbs/';// check if the form is submittedif(isset($_POST['upload'])){ // get the input from $_POST variable // trim all input to remove extra spaces $title = trim($_POST['txtTitle']); $description = trim($_POST['txtDescription']); $url = trim($_POST['txtUrl']); $thumbnail = trim($_POST['thumbnailfile']); // escape the message ( if it's not already escaped ) if(!get_magic_quotes_gpc()) { $title = addslashes($title); $description = addslashes($description); } // if the visitor do not enter the url // set $url to an empty string if ($url == 'http://') { $url = ''; }//adding thumbnail stuffif(isset($_POST['upload'])){ $fileName = $_FILES['thumbnailfile']['name']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } // prepare the query string $query = "INSERT INTO guestbook (title, description, url, thumbnail, entry_date) " . "VALUES ('$title', '$description', '$url', '$fileName', current_date)"; // execute the query to insert the input to database // if query fail the script will terminate mysql_query($query) or die('Error, query failed. ' . mysql_error()); // redirect to current page so if we click the refresh button // the form won't be resubmitted ( as that would make duplicate entries ) header('Location: ' . $_SERVER['REQUEST_URI']); // force to quit the script. if we don't call exit the script may // continue before the page is redirected exit;}?><html><head><title>Add a Plug</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" type="text/css" href="styles/styles.css"><script language="JavaScript">/* This function is called when the 'Sign Guestbook' button is pressed Output : true if all input are correct, false otherwise*/function checkForm(){ // the variables below are assigned to each // form input var gname, gemail, gurl, gmessage; with(window.document.guestform) { gtitle = txtTitle; gdescription = txtDescription; gurl = txtUrl; gthumbnail = thumbnailfile; } // if name is empty alert the visitor if(trim(gtitle.value) == '') { alert('Please enter a title'); gname.focus(); return false; } // alert the visitor if email is empty or the format is not correct else if(trim(gdescription.value) != '' && !isEmail(trim(gdescription.value))) { alert('Please enter a description'); gemail.focus(); return false; } // alert the visitor if message is empty else if(trim(gthumbnail.value) == '') { alert('Please Add a Thumbnail'); gthumbnail.focus(); return false; } else { // when all input are correct // return true so the form will submit return true; }}/*Strip whitespace from the beginning and end of a stringInput : a stringOutput : the trimmed string*/function trim(str){ return str.replace(/^\s+|\s+$/g,'');}</script></head><body><form method="post" enctype="multipart/form-data" name="plugs"> <table width="550" border="0" cellpadding="2" cellspacing="1"> <tr> <td width="100">Title</td> <td> <input name="txtTitle" type="text" id="txtTitle" size="30" maxlength="30"></td> </tr> <tr> <td width="100">Description</td> <td> <input name="txtDescription" type="text" id="txtDescription" size="200" maxlength="200"></td> </tr> <tr> <td width="100">URL</td> <td> <input name="txtUrl" type="text" id="txtUrl" value="http://" size="30" maxlength="50"></td> </tr> <tr> <td width="100">Thumbnail</td> <td> <input name="thumbnailfile" type="file" class="box" id="thumbnailfile"></td></tr> <tr> <td width="100"> </td> <td> <input name="upload" type="submit" id="upload" value="Plug" onClick="return checkForm();"></td> </tr></table></form>[/code]Thanks again and sorry for the lengthy code... :) Link to comment https://forums.phpfreaks.com/topic/4492-unexpected/ Share on other sites More sharing options...
AndyB Posted March 9, 2006 Share Posted March 9, 2006 Usually means that somewhere there's an unclosed curly bracket ... quite where } belongs isn't evident (so maybe it's in the code that's included) Link to comment https://forums.phpfreaks.com/topic/4492-unexpected/#findComment-15645 Share on other sites More sharing options...
davinci Posted March 9, 2006 Author Share Posted March 9, 2006 [!--quoteo(post=353112:date=Mar 8 2006, 09:45 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 8 2006, 09:45 PM) [snapback]353112[/snapback][/div][div class=\'quotemain\'][!--quotec--]Usually means that somewhere there's an unclosed curly bracket ... quite where } belongs isn't evident (so maybe it's in the code that's included)[/quote]Thanks! After knowing what to look for I found that I had left out a } !!I appreciate the help. Link to comment https://forums.phpfreaks.com/topic/4492-unexpected/#findComment-15646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.