Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-07-2007, 11:21 PM   #16 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Code Problems

SDE,

The Upload code on post #13 keeps coming up with the following error, why is this?

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Documents and Settings\DVC Customer\Desktop\xampplite\htdocs\Upload.php on line 59

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-07-2007, 11:47 PM   #17 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
the line:
PHP Code:
      $result mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."',mysql_real_escape_string($_POST['caption'])"); 
should have been
PHP Code:
      $result mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."','".mysql_real_escape_string($_POST['caption']."')"); 
Please be more alert when you just snatch some code up, this is even an easy one , the error points out the line number and all.
You can't expect everything you're beein presented with as beeing handed over on a silverplatter.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-07-2007, 11:58 PM   #18 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

I know, but this is pretty much the first time i have had anything to do with PHP. I still in the process of learning the different error messages etc.

Please be gentle with me :-)

Many Thanks, much appreciated!!!
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 12:08 AM   #19 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

I now keep getting the following error:

Parse error: parse error, unexpected ';' in C:\Documents and Settings\DVC Customer\Desktop\xampplite\htdocs\Upload.php on line 59

but when i remove the ';', the the below message appears, whys this?
**I'm learning from this**

Parse error: parse error, unexpected T_STRING in C:\Documents and Settings\DVC Customer\Desktop\xampplite\htdocs\Upload.php on line 61

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 05:26 AM   #20 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
hey salch.. i understand. once you get the hang of debugging PHP code, you will find the errors are quite informative. parse error obviously means the syntax is messed up somewhere.

whenever you get a situation where the line reported in the error looks good, then it's a good sign that maybe a control structure, or quote was not closed above that section of code.

i don't know the code and the line numbers of your script, so i wouldn't be able to tell you from this.

take a look above it and make sure any strings and control structure are closed above it.
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 09:51 AM   #21 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery - Code

SDE,

OK, I Haven't Got a Clue!!!
Can you find anything wrong with the below code, the error currently being display, is as follows:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Upload.php on line 59

Code:
  <?php
$errors = array();

// error checking
if (empty($_FILES['file'])) {
    $errors[] = 'no file uploaded';
}
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
    $errors[] = 'Possible file upload attack';
}

switch ($_FILES['file']['error'])
{
    case UPLOAD_ERR_INI_SIZE:
        $errors[] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 

    case UPLOAD_ERR_FORM_SIZE:
        $errors[] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';

    case UPLOAD_ERR_PARTIAL:
        $errors[] = 'The uploaded file was only partially uploaded.';

    case UPLOAD_ERR_NO_FILE:
        $errors[] = 'No file was uploaded.';

    case UPLOAD_ERR_NO_TMP_DIR:
        $errors[] = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
 
    case UPLOAD_ERR_CANT_WRITE:
        $errors[] = 'Failed to write file to disk. Introduced in PHP 5.1.0.';

    case UPLOAD_ERR_EXTENSION:
        $errors[] = 'File upload stopped by extension. Introduced in PHP 5.2.0.';
}

// your error checking
if ($_FILES["file"]["type"] != "image/gif" || $_FILES["file"]["type"] != "image/jpeg") {
    $errors[] = 'Wrong image format.';
}

if ($_FILES["file"]["size"] > 20000) {
    $errors[] = 'File is too large.';
}

if ($count($errors)==0) {
    
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"])) {
        
      echo $_FILES["file"]["name"] . " already exists. ";
      
    } else {
        
      // add record to database
      $result = mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."',mysql_real_escape_string($_POST['caption'])");
      
      move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    
} else {

  echo "<b>Errors</b><br />";
  
  foreach ($errors as $each) {
      echo $each."<br />";
  }
}
?>
Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 09:55 AM   #22 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
maybe here?
PHP Code:
$result mysql_query("insert into images (filename, caption)
values('"
.$_FILES["file"]["name"]."','".mysql_real_escape_string($_POST['caption']."')"); 
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 10:03 AM   #23 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Yes, but whats wrong with it?

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 10:05 AM   #24 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
comon now, look at the difference in what i posted vs the original.
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 10:21 AM   #25 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

Oh, sorry is that new code? i though it was the same as what i have already got.
Yes, is works fine, brilliant, only now i am greeted with another error, this time as follows:

Parse error: parse error, unexpected T_STRING in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Upload.php on line 61

Code:
  <?php
$errors = array();

// error checking
if (empty($_FILES['file'])) {
    $errors[] = 'no file uploaded';
}
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
    $errors[] = 'Possible file upload attack';
}

switch ($_FILES['file']['error'])
{
    case UPLOAD_ERR_INI_SIZE:
        $errors[] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 

    case UPLOAD_ERR_FORM_SIZE:
        $errors[] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';

    case UPLOAD_ERR_PARTIAL:
        $errors[] = 'The uploaded file was only partially uploaded.';

    case UPLOAD_ERR_NO_FILE:
        $errors[] = 'No file was uploaded.';

    case UPLOAD_ERR_NO_TMP_DIR:
        $errors[] = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
 
    case UPLOAD_ERR_CANT_WRITE:
        $errors[] = 'Failed to write file to disk. Introduced in PHP 5.1.0.';

    case UPLOAD_ERR_EXTENSION:
        $errors[] = 'File upload stopped by extension. Introduced in PHP 5.2.0.';
}

// your error checking
if ($_FILES["file"]["type"] != "image/gif" || $_FILES["file"]["type"] != "image/jpeg") {
    $errors[] = 'Wrong image format.';
}

if ($_FILES["file"]["size"] > 20000) {
    $errors[] = 'File is too large.';
}

if ($count($errors)==0) {
    
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"])) {
        
      echo $_FILES["file"]["name"] . " already exists. ";
      
    } else {
        
      // add record to database  
      $result = mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."','".mysql_real_escape_string($_POST['caption']."')")

      move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    
} else {

  echo "<b>Errors</b><br />";
  
  foreach ($errors as $each) {
      echo $each."<br />";
  }
}
?>
Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 10:49 AM   #26 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
so look at line 61 and tell me what's wrong with it. if you say you have no idea, and nothing more.. then you're not really showing you are trying to learn this stuff.

ask very specific questions about the line if you don't understand what it is doing. i'd be happy to answer your questions.

i'll go out of my way to help someone learn, but i get paid for just plain writing and debugging code.
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 11:11 AM   #27 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

Is it due to the fact there is no ";" at the end of the following line?

$result = mysql_query("insert into images (filename, caption)

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 11:17 AM   #28 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
that is what i thought it was after looking at it. hope it works.
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 11:24 AM   #29 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

No, it doesn't work!!!
Apart from the current solution, i haven't got a clue.

I then get the following message:

Parse error: parse error, unexpected ';' in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Upload.php on line 59

Yourself?

Many Thanks, much appreciated!!!
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 02-08-2007, 02:17 PM   #30 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
Why did restart this question yesterday on another website here?
http://www.devhardware.com/forums/pr...se-124232.html

If you really want to learn why aren't you listening?

Especially, since you have experience with C programming as of 2005 you should understand debugging.
http://www.gidforums.com/t-6983.html
http://www.programmingtalk.com/showthread.php?t=22100
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make a search engine for your website with PHP zhisede PHP 3 10-25-2005 07:54 AM
PHP 5.0.4 and 4.3.11 Released sde Code Newbie News 0 04-20-2005 10:56 AM
PHP to Flash control panel roccoman PHP 1 11-24-2004 08:10 AM
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 04:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting