PDA

View Full Version : whats wrong with these scripts i made?????


pattox2k1
05-20-2002, 07:30 AM
first of all i have this number guessing game i made and this is the code i have:


<?php
$num_to_guess=73;
$message="";
if(!isset($guess))
$message="Welcome to the number guessing game, please type in a guess in the box below. All numbers are between 1 and 100 and will change evry week. HINT: This number is over 50 and under 80.";
elseif ($guess>$num_to_guess)
$messgae="$guess is too high, try a lower number";
elseif ($guess<$num_to_guess)
$message="$guess is too low, try a higher number:;
else//must be equivalent
$message="Well done!";
?>

<html>
<head>
<title>The Number Guessing Game</title>
</head>
<body>
<h1>
<?php print $message ?>
</h1>
<form method="POST">
Thye in your guess here: <input type="text" name="guess">
</form>
</body>
</html>


and the server gives me this error:


Parse error: parse error in /mnt/host-users/homeworkhh/guess.php on line 11




i can't find any errors..... and my second problem is on my upload script, my code is:


<HTML>
<HEAD>
<TITLE>Your Site Uploader</TITLE>
<?php
$file_dir= "/path/to/fokder/uploads";
$file_ url= "http://www.yoursite.com/uploads";

foreach( $HTTP_POST_FILES as $file_name => $file_array ) { print "path: ".$file_array['tmp_name']."<BR>\n"; print
"name: ".$file_array['name']."<BR>\n"; print "type:
".$file_array['type']."<BR>\n"; print "size: ".$file_array['size']."<BR>\n"; if
( is_uploaded_file( $file_array['tmp_name;] ) &amp;&amp; $file_array['type'] ==
"image/gif' ) { move_uploaded_file( $file_array['tmp_name'],
"$file_dir/$file_name") or die ("Couldn't copy"); print "<IMG
src='\"$file_url/$file_name\"'>
<P>\n\n"; } } ?&gt; </P>
<FORM method=post encType=multipart/form-data>
<P><INPUT type=hidden value=100024 name=MAX_FILE_SIZE> <INPUT type=file
name=fupload><BR><INPUT type=submit value="Upload" name="Upload File">
</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;</P>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=1>
<TBODY>
<TR>
<TD>



and the server gives me this error (when all variables are filled in):


Parse error: parse error in /mnt/host-users/homeworkhh/mtuploader.php on line 6


and again, i cant find any errors.....i have even sent that one to others and they cant find anything wrong with it :( can someone PLZ help me???

Logician
05-20-2002, 09:18 AM
1- Missing " at the end of line:
$message="$guess is too low, try a higher number:;
should be:
$message="$guess is too low, try a higher number:";

2- Unnecessary space at:
$file_ url= "http://www.yoursite.com/uploads";
Should be:
$file_url= "http://www.yoursite.com/uploads";

;)

pattox2k1
05-20-2002, 09:24 AM
ok thx for #1 that worked (jus a typo, typed it up quickly) but i did what u say on #2 but it say this error:


Parse error: parse error, expecting `']'' in /mnt/host-users/homeworkhh/mtuploader.php on line 11





what might it be????

Logician
05-20-2002, 09:38 AM
$file_array['tmp_name;]
is wrong. Should be:
$file_array['tmp_name'];

These are very easy to catch syntax errors. Please check your code carefully, I'm sure you can easily correct them..

Regards,
Logician

pattox2k1
05-20-2002, 09:44 AM
ok thx ;) i typed 1 up quickly and one late at night so i wouldnt know, and i aint that good wif PHP and they r my first scripts so i wouldnt know where to look for errors :(.....BTW i jus did what u say and i get this error:


Parse error: parse error in /mnt/host-users/homeworkhh/mtuploader.php on line 11







PLZ help...........

Logician
05-20-2002, 10:15 AM
file_array['type'] == "image/gif'
is wrong. Should be:
file_array['type'] == "image/gif"

You better use this code below. I edited all your syntax errors so you wouldnt get any parse errors with this one. (However this only applies to syntax errors, I cant say anything with your coding algorithm.

And may I suggest you begining PHP from the begining with learning the basics first? You are going too fast to write this script if you really dont know how to correct these simple errors. My 2 cents..

-- cut ---
$file_dir= "/path/to/fokder/uploads";
$file_url= "http://www.yoursite.com/uploads";

foreach( $HTTP_POST_FILES as $file_name => $file_array )
{
print "path: ".$file_array['tmp_name']."<BR>\n";
print "name: ".$file_array['name']."<BR>\n";
print "type: ".$file_array['type']."<BR>\n";
print "size: ".$file_array['size']."<BR>\n";
$filename=(string)$file_array['tmp_name'];
$filetype=(string) $file_array['type'];
if (is_uploaded_file($filename) AND $filetype=="image/gif" )
{

$log_v1=$file_array['tmp_name']; //$log_v2=$file_dir."/".$file_name;

move_uploaded_file($log_v1, $log_v2) or die ("Couldn't copy");

print "<IMG src='\"$file_url/$file_name\"'><P>\n\n"; }
}
-- cut ---

pattox2k1
05-20-2002, 10:23 AM
that dont work....neither of them :(

Logician
05-20-2002, 10:27 AM
pattox2k1, the code I posted is free of syntax errors, you wouldnt get any parse errors or anything with that code.

But as I said, I dont know if it works as it should be or not, because I am not aware of what you are trying to do with this script. You asked the correction of the errors you get and I fixed them. If your algorithm is wrong, the code might not do what you are aiming to do, even if it gives no errors..

pattox2k1
05-22-2002, 06:08 AM
ok then i will try and type it up again and see what happens........if it dont work i will ask someone else for help ;)