Welcome to WebmasterWorld Guest from 54.221.131.67

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

why am I getting this error?

     
1:27 am on Dec 23, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2005
posts:13
votes: 0


I am trying to automatically generate thumbnails. I have this script but I keep getting the error below:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Here is the code for the script.

<html>
<head><title>Enter Name and Descriptions of Pics</title></head>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">

<?php
$dbh=mysql_connect("localhost", "username", "password") or die ('I cannot connect to the database.');
mysql_select_db("db");

$uploaddir = '/home/username/public_html/images/';
$tot = count($userfile);
$num = 0;
for($q=0;$q<$tot;$q++){

if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);

while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
}

if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic)) {
$sql = "INSERT INTO `pics` ( `pic_id` , `name` , `descrip` )VALUES ('$new_id', NULL , NULL);";
mysql_query($sql);
} else {
print "<strong>$_FILES['userfile']['name'][$q]</strong> did not upload!";
}

$new_thumb = "thumbs/$new_pic";
$sourcefile = "$uploaddir$new_pic";
$picsize = getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize;

if ($source_x > $source_y){
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}

$targetfile = "$uploaddir$new_thumb";
$jpegqual = 75;
$source_id = imagecreatefromjpeg("$sourcefile");
$target_id = imagecreatetruecolor($dest_x, $dest_y);
$target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg($target_id,"$targetfile",$jpegqual);
?>
<div style="clear: both;">
<a href="/images/<?=$new_pic?>">
<img src="/images/<?=$new_thumb?>" style="float: left" />
</a>
<strong><?=$_FILES['userfile']['name'][$q]?></strong><br /><br />
<strong>Name:</strong><br />
<input type="text" name="pic_name[<?=$num?>]" /><br /><br />
<strong>Description:</strong><br />
<textarea name="descrip[<?=$num?>]"></textarea>
<input type="hidden" name="pic_id[<?=$num?>]" value="<?=$new_id?>" />
</div>
<?php
}
?>
<input type="submit" value="Click to Save Descriptions" />
</form>
</body>
</html>

1:38 am on Dec 23, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 13, 2003
posts:775
votes: 0


You don't need a semicolon at the end of the sql statement. So this

$sql = "INSERT INTO `pics` ( `pic_id` , `name` , `descrip` )VALUES ('$new_id', NULL , NULL);";

should be this...

$sql = "INSERT INTO `pics` ( `pic_id` , `name` , `descrip` ) VALUES ('$new_id', NULL , NULL)";

If that doesn't fix the problem then you'll need to tell us the line number of the error message.

Tim

1:57 am on Dec 23, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


You can also change this line:

print "<strong>$_FILES['userfile']['name'][$q]</strong> did not upload!";

To this:

print "<strong>{$_FILES['userfile']['name'][$q]}</strong> did not upload!";

dc

1:17 am on Dec 24, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2005
posts:13
votes: 0


Ok, I made those two changes and I am not getting that error but for some reason it doesn't appear to have fully worked. There isn't an entry in my DB and the file isn't there. <shrug> Could it be a permissions problem.
2:18 am on Dec 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


Change this line:

mysql_query($sql);

to this:

mysql_query($sql) or die(mysql_error());

and see if you get an .sql error. That may give you a clue to the problem.

dc

11:52 pm on Dec 24, 2005 (gmt 0)

New User

10+ Year Member

joined:Dec 7, 2005
posts:13
votes: 0


Ok here is my code with the changes. I also put the "or die" functionality on the SQL calls and that didn't shed any light on anything. Could it be a permissions problem. The file never seems to be getting placed in the directory set aside. I changed the parameters to mysql_connect to protect my site but if anyone can tell me what I am doing wrong I'd appreciate. When I call this in the form, it just jumps to the "Click to Save Description".

By the way this is based off the code in the thread:

[webmasterworld.com...] msg 29.

<html>
<head><title>Enter Name and Descriptions of Pics</title></head>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">

<?php
$dbh=mysql_connect("XXXX", "XXXXXX", "XXXXXX") or die ('I cannot connect to the database.');
mysql_select_db("theheaders");

$uploaddir = './images/';
$tot = count($userfile);
$num = 0;
for($q=0;$q<$tot;$q++){

if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());

while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
}

if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic))
{
$sql = "INSERT INTO `pics` ( `pic_id` , `name` , `descrip` )VALUES ('$new_id', NULL , NULL)";
mysql_query($sql) or die(mysql_error());
}
else
{
print "<strong>{$_FILES['userfile']['name'][$q]}</strong> did not upload!";
}

$new_thumb = "thumbs/$new_pic";
$sourcefile = "$uploaddir$new_pic";
$picsize = getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize;

if ($source_x > $source_y){
$dest_x = 200;
$dest_y = 150;
} else {
$dest_x = 150;
$dest_y = 200;
}

$targetfile = "$uploaddir$new_thumb";
$jpegqual = 75;
$source_id = imagecreatefromjpeg("$sourcefile");
$target_id = imagecreatetruecolor($dest_x, $dest_y);
$target_pic = imagecopyresized($target_id,$source_id,0,0,0,0,$dest_x,$dest_y,$source_x,$source_y);
imagejpeg($target_id,"$targetfile",$jpegqual);
?>
<div style="clear: both;">
<a href="/images/<?=$new_pic?>">
<img src="/images/<?=$new_thumb?>" style="float: left" />
</a>
<strong><?=$_FILES['userfile']['name'][$q]?></strong><br /><br />
<strong>Name:</strong><br />
<input type="text" name="pic_name[<?=$num?>]" /><br /><br />
<strong>Description:</strong><br />
<textarea name="descrip[<?=$num?>]"></textarea>
<input type="hidden" name="pic_id[<?=$num?>]" value="<?=$new_id?>" />
</div>
<?php
}
?>
<input type="submit" value="Click to Save Descriptions" />
</form>
</body>
</html>