I want to make a thread for my site for php scripting errors. I am still new to php and know I mite get a junk load of errors from each page or so. I want to ask as my first qustion. I get this error here http://www.postmysite.frih.net/inputing.php What does this mean? Your help would be most thankful the best I can do for you if you help me is put you on the credits on post my site credits for everyone to see.
Thank you. 
Well ... you could have posted the error here and the part of the script that generates the error. The error is | Quote: |
| Parse error: syntax error, unexpected T_STRING in /home/postmysi/domains/postmysite.frih.net/public_html/inputing.php on line 11 |
This means PHP found a string (on line 11) when it didn't expect one. It may happen when you forget to close a previous quote, as in | Code: |
<?php
$name = "postmysite;
echo "Hello, $name";
?> |
Note there is no closing quote on line 2. For this script PHP says | Quote: |
| Parse error: parse error, unexpected T_STRING in /var/www/tmp/parse.php on line 3 |
The code above slightly reformatted is the same as | Code: |
<?php
$name = "postmysite;\necho "
Hello, $name";
?> |
PHP is expecting a semicolon and not the "Hello" at the start of line 3.
I also have html codes in the script does the line 11 start in after <?php or is it the hole page? Also if it helps I will post the code
| Code: |
<DOCTYPE html PUBLIC "-//w3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtmll1/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content type" content="text/html; charset=iso-8859-1" />
<title>Submit a site</title>
</head>
<body>
<?php//Script 11.6 - submit.php
ini_set (display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset ($_POST['submit'] {
if (!$problem) {//if there was any problems...
if($fp = fopen ('../sites/sites.txt', ''ab')) {//Open the file.
//Create the data to be written.
$dir = time() . rand (0, 4596);
$data = $_POST['sitename'] . "\t" . crypt($_POST['password']) . "\t" . $dir . "\n";
//\r\n on Windows
//write the data and close up!
fwrite ($fp, $data);
fclose ($fp);
//Create the directory.
mkdir ("../users/$dir");
//Print a message
Pront '<p>You have submited a site!!!! ;)</p>';
} else {//couldn't write to the file.
print '<p> Sorry, but a system error happend durring the submiting! :0</p>';
}
} else {//Forgot a field.
print '<p>Please try again! :(</p>';
}
} else {//display the form.
//leave PHP and display the form.
?>
<form action="inputing.php" method="post">
Site URL: <input type="text" name="siteurl" size="30" /><br />
Site Descritpion: <input type="text" name="sitedes" size="30" /><br />
<input type="submit" name="submit" value="Sumbit The Site!">
</form>
<?php>
}//END Of SUBMIT IF.
?>
</body>
</html> |
| postmysite.com wrote: |
| I also have html codes in the script does the line 11 start in after <?php or is it the hole page? Also if it helps I will post the code |
Yes, it helps. It's line 11 of the whole page
Wow!!! So many errors
Check my ### comments before the lines with errors
| Code: |
<DOCTYPE html PUBLIC "-//w3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtmll1/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content type" content="text/html; charset=iso-8859-1" />
<title>Submit a site</title>
</head>
<body>
<?php//Script 11.6 - submit.php
### no opening single quote, you mean ini_set ('display_errors', 1);
ini_set (display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
### no close parenthesis, you mean if (isset($_POST['submit'])) {
if (isset ($_POST['submit'] {
### instruction and comment are opposite
if (!$problem) {//if there was any problems...
### watch your quotes
if($fp = fopen ('../sites/sites.txt', ''ab')) {//Open the file.
//Create the data to be written.
$dir = time() . rand (0, 4596);
$data = $_POST['sitename'] . "\t" . crypt($_POST['password']) . "\t" . $dir . "\n";
//\r\n on Windows
//write the data and close up!
fwrite ($fp, $data);
fclose ($fp);
//Create the directory.
mkdir ("../users/$dir");
//Print a message
### "Pront" is not a PHP function
Pront '<p>You have submited a site!!!! ;)</p>';
} else {//couldn't write to the file.
print '<p> Sorry, but a system error happend durring the submiting! :0</p>';
}
} else {//Forgot a field.
print '<p>Please try again! :(</p>';
}
} else {//display the form.
//leave PHP and display the form.
?>
<form action="inputing.php" method="post">
Site URL: <input type="text" name="siteurl" size="30" /><br />
Site Descritpion: <input type="text" name="sitedes" size="30" /><br />
<input type="submit" name="submit" value="Sumbit The Site!">
</form>
### What's that ">" right after <?php
<?php>
### I didn't try to match the { and }.
### Possibly they match :)
}//END Of SUBMIT IF.
?>
</body>
</html> |
Cool, thanks for your input I will try to correct it after I enjoy some rain that is in my town now. Also on that <?php> I am used to wrighting html scripts alot so you can see why I did that.
Strange it keeps showing the same error and I checked the lines and I did what you told me but it seems still not to work here is a update
| Code: |
<DOCTYPE html PUBLIC "-//w3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtmll1/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content type" content="text/html; charset=iso-8859-1" />
<title>Submit a site</title>
</head>
<body>
<?php//Script 11.6 - inputing.php
ini_set (display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
if (isset($_POST['submit'])) {
if (!$problem) {//if there was any problems...
if($fp = fopen ('../sites/sites.txt', ''ab')) {//Open the file.
//Create the data to be written.
$dir = time() . rand (0, 4596);
$data = $_POST['sitename'] . "\t" . crypt($_POST['password']) . "\t" . $dir . "\n";
//\r\n on Windows
//write the data and close up!
fwrite ($fp, $data);
fclose ($fp);
//Create the directory.
mkdir ("../users/$dir");
//Print a message
Print '<p>You have submited a site!!!! ;)</p>';
} else {//couldn't write to the file.
print '<p> Sorry, but a system error happend durring the submiting! :0</p>';
}
} else {//Forgot a field.
print '<p>Please try again! :(</p>';
}
} else {//display the form.
//leave PHP and display the form.
?>
<form action="inputing.php" method="post">
Site URL: <input type="text" name="siteurl" size="30" /><br />
Site Descritpion: <input type="text" name="sitedes" size="30" /><br />
<input type="submit" name="submit" value="Sumbit The Site!">
</form>
<?php
}//END Of SUBMIT IF.
?>
</body>
</html> |
You're still missing the opening single quote in the "ini_set" call around line 11.
You have {ini_set (display errors', 1);}
Should be {ini_set ('display errors', 1);}
When you get an error like "unexpected T_STRING" it usually means you've forgotten a quote somewhere which makes it impossible for php to interpret the script properly.
- Walkere
It is still complaning about this line in my script!
| Code: |
| ini_set ('display errors', 1);} |
| postmysite.com wrote: |
It is still complaning about this line in my script!
| Code: | | ini_set ('display errors', 1);} |
|
I suggest you read the PHP manual, starting with the section about strings.
The errors you still have in your script are very basic errors. You certainly do not expect anybody to correct every small error you let through ...
Imagine you want to display the double of a quantity, and you manage this code | Code: |
| echo $quantity + 2; |
but it will not display double the quantity (if $quantity is 10 it will not print 20 but 12 instead). It is much better if you can solve these little problems by yourself rather than relying on the frihost community to do it for you.
Happy Coding
PS: The "}" should not be part of the ini_set() line
Whoops. I didn't mean for you to actually put the curly braces into the code. I was just using those to separate it from the rest of the message. I guess I'll just stick with the standard code formatting in the future.
And like HexKid said, check out some of the documentation and try to learn the proper syntax to avoid these little errors. We're happy to help, but if you can eliminate them early on you'll save everyone a bunch of time.
- Walkere
I find this strange I remove the code that tells if the site has been submited and now php is saying every thing in the php script area all has a error. Why is it doing this?
| postmysite.com wrote: |
| I find this strange I remove the code that tells if the site has been submited and now php is saying every thing in the php script area all has a error. Why is it doing this? |
What editor do you use for editing your scripts?
I think Notepad is great (there are much greater substitutes) ... but try a code and syntax highlighting editor.
I am using notepad are php editors good at detecting php script errors?
| postmysite.com wrote: |
| I am using notepad are php editors good at detecting php script errors? |
Can you spot the error in this script?
It's a very basic script and I'm sure you can spot the error.
That was the Notepad view.
Now try the same script with syntax highlighting 
| Code: |
<?php
$hello = 'Hello';
print("$hello ");
$name = 'hexkid's test';
print($name);
?> |
I have not had the chance with playing around with printing in php if I did want to make text areas I use html. But I will tell you what I think I mite know with the script.
in line 3 I think the "" should be ' ' since I have not yet seen a php script have those in it. Also on line 4 I think there needs to be )) after $name if I am thinking mysql programming. That is all I can say. Well now I will look at the highlited text.
EDIT I mist 2 I thought (comand) does not always has to be in all comands like ($hello) on line 3.
Well atleast I can always wach out for this stuff when I get into web site desgin class in high school hopfuly they will even teach php.