Jump to content


Photo

unexpected $


  • Please log in to reply
2 replies to this topic

#1 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 09 March 2006 - 02:38 AM

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?

<?php
// include the database configuration and
// open connection to database
include 'library/config.php';
include 'library/opendb.php';

$uploadDir = 'media/thumbs/';

// check if the form is submitted
if(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 stuff

if(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 string
Input  : a string
Output : 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">&nbsp;</td>
   <td> 
    <input name="upload" type="submit" id="upload" value="Plug" onClick="return checkForm();"></td>
 </tr>
</table>
</form>

Thanks again and sorry for the lengthy code... :)

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 March 2006 - 02:45 AM

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)
Legend has it that reading the manual never killed anyone.
My site

#3 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 09 March 2006 - 02:55 AM

[!--quoteo(post=353112:date=Mar 8 2006, 09:45 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Mar 8 2006, 09:45 PM) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users