|
 |
|
 |
02-07-2007, 11:21 PM
|
#16 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-07-2007, 11:47 PM
|
#17 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
|
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.
|
|
|
02-07-2007, 11:58 PM
|
#18 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-08-2007, 12:08 AM
|
#19 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-08-2007, 05:26 AM
|
#20 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
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
|
|
|
02-08-2007, 09:51 AM
|
#21 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-08-2007, 09:55 AM
|
#22 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
maybe here?
PHP Code:
$result = mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."','".mysql_real_escape_string($_POST['caption']."')");
__________________
Mike
|
|
|
02-08-2007, 10:03 AM
|
#23 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Yes, but whats wrong with it?
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
02-08-2007, 10:05 AM
|
#24 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
comon now, look at the difference in what i posted vs the original.
__________________
Mike
|
|
|
02-08-2007, 10:21 AM
|
#25 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-08-2007, 10:49 AM
|
#26 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
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
|
|
|
02-08-2007, 11:11 AM
|
#27 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
02-08-2007, 11:17 AM
|
#28 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,444
|
that is what i thought it was after looking at it. hope it works.
__________________
Mike
|
|
|
02-08-2007, 11:24 AM
|
#29 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
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?
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 04:08 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|