Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,491 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,709 people online right now. Registration is fast and FREE... Join Now!




Problems uploading files to MySQL table

 
Reply to this topicStart new topic

Problems uploading files to MySQL table, Parse error: syntax error, unexpected $end in C:\xampp\

jeansymolanza
24 Feb, 2008 - 03:05 PM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
I keep getting the error

"Parse error: syntax error, unexpected $end in C:\xampp\htdocs\ilovephysics\admin\addfile2.php on line 292"

whenever I try and upload a file to my SQL database. This is what I've done so far.

Form code (addfile.php):

CODE
<form name="form1" method="post" action="addfile2.php" enctype="multipart/form-data">
            <table border="0" cellspacing="2" cellpadding="2" width="800px">
              <tr>
                <td width="136">Date</td>
                <td width="650"><label>
                  <input name="date" type="text" readonly="readonly" id="date" value="<? echo date("Y/m/d");?>" size="25">
                </label></td>
              </tr>
              <tr>
                <td>Time</td>
                <td><input name="time" type="text" readonly="readonly" id="time" value="<?
                   $tim = localtime(time(),true);
echo($tim['tm_hour'].":".$tim['tm_min'].":".$tim['tm_sec']);
                   ?>" size="25"></td>
              </tr>
              <tr>
                <td>Title</td>
                <td><input name="title" type="text" id="title" size="50"></td>
              </tr>

              <tr>
                <td>Category</td>
                <td><select name="category" id="category">
                    <option selected>-- None or Other --</option>
                    <option>Acoustics</option>
                    <option>Astronomy</option>
                    <option>Astrophysics</option>
                    <option>Atomic Physics</option>
                    <option>Biophysics</option>
                    <option>Chaos</option>
                    <option>Chemical Physics</option>
                    <option>Computational Physics</option>
                    <option>Chaos</option>
                    <option>Cosmology</option>
                    <option>Cryophysics</option>
                    <option>Crystallography</option>
                    <option>Electromagnetism</option>
                    <option>Electronics</option>
                    <option>Fluid Dynamics</option>
                    <option>Geophysics</option>
                    <option>High Energy Physics</option>
                    <option>High Pressure Physics</option>
                    <option>Laser Physics</option>
                    <option>Mathematical Physics</option>
                    <option>Mechanics</option>
                    <option>Molecular Physics</option>
                    <option>Nanotechnology</option>
                    <option>Nuclear Physics</option>
                    <option>Light Physics</option>
                    <option>Particle Physics</option>
                    <option>Plasma Physics</option>
                    <option>Quantum Electrodynamics</option>
                    <option>Quantum Physics</option>
                    <option>Quantum Optics</option>
                    <option>Quantum Field Theory</option>
                    <option>Quantum Gravity</option>
                    <option>Relativity</option>
                    <option>Statistical Mechanics</option>
                    <option>String Theory</option>
                    <option>Thermodynamics</option>
                    <option>Weather Physics</option>
                </select></td>
              </tr>
              <tr>
                <td valign="top">Description</td>
                <td><label>
                  <textarea name="description" cols="50" rows="8" id="description"></textarea>
                </label></td>
              </tr>

              <tr>
                <td>File Location </td>
                <td><table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
                  <tr>
                    <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="1000000">
                        <input name="userfile" type="file" id="userfile">                    </td>
                    </tr>
                </table></td>
              </tr>
            </table>
            <p>
              <input name="Submit" type="submit" value="Submit">
              <script type="text/javascript">
<!--
function betterMo() {
if (confirm("Are you sure you want to clear form?")) {
document.fori.reset();
}
}
-->
              </script>
              <input name="Reset" type="reset" id="Reset" value="Reset" onClick="java script: betterMo();return false">
                </p>
            </p>
          </form>


addfile2.php (which is meant to process the file upload)

CODE


<?php
//connect to database//
$db_name="ilovephysics";
$connection = @mysql_connect("localhost","root","password") or die(mysql_error());
$db = @mysql_select_db($db_name,$connection) or die(mysql_error());

//collect data from previous page and assign to variables//
$date=$_POST['date'];
$time=$_POST['time'];
$title=$_POST['title'];
$category=$_POST['category'];
$description=$_POST['description'];

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

//assign SQL query to a variable//
$sql="INSERT INTO tbl_files (`date`, `time`, `title`, `category`, `description`, `type`, `size`, `content`) VALUES
('$date', '$time', '$title', '$category', '$description', '$fileType', '$fileSize', '$content')";

//run the query//
$result=@mysql_query($sql) or die(mysql_error());
?>



This is the confirmation that the user receives (also on addfile2.php):

CODE


<td width="789" align="center" valign="top"><table width="800" border="0" align="center" cellpadding="1" cellspacing="1">
      <tr>
        <td align="left" valign="top"><p align="left"><span class="style5">Add File</span></p>
          <p align="left"><? echo "The file $fileName has been successfully uploaded! "?>Click <a href="showallfile.php">here</a> to return to the file management page. </p></td>



Any help would be very much appreciated. Thanking you in advance!
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Problems Uploading Files To MySQL Table
24 Feb, 2008 - 05:46 PM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

the error would usually indacate is one to many brakets. {}

CODE

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: Problems Uploading Files To MySQL Table
24 Feb, 2008 - 10:15 PM
Post #3

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
Oh ok, I don't understand how there can be too many brackets though.

Thanks for the reply.
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Problems Uploading Files To MySQL Table
25 Feb, 2008 - 07:17 AM
Post #4

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

you are missing one, one to many start brackets, and no ending one.
i posted the code where you did not end it.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:36PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month