error! why? please help!
Moderator: General Moderators
error! why? please help!
hi guys I am getting this error what does it mean?
Parse error: parse error, unexpected T_STRING in d:\InetPub\wwwroot\wask\news.php on line 1
the full code for this page is below
<?
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "editpass") {
//First let's recompile that line with the pipe symbols so we can reinsert it
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
$data = file('news.txt');
$data[$id] = $line;
//the next line makes sure the $data array starts at the beginning
reset($data);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item Edited!<BR><BR>\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
} else {
echo "Bad password!\n";
exit;
}
}
if($action == "edit") {
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
//the next line is to reverse the process of turning the end of lines into breaking returns
$news = str_replace("<BR>","\r\n",$pieces[2]);
echo "Make the changes you would like and press save.<BR>\n";
echo "<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
echo "Name:<BR>\n";
echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
echo "The News:<BR>\n";
echo "<TEXTAREA NAME=\"news\" COLS=\"40\" ROWS=\"5\">".$news."</TEXTAREA><BR><BR>\n";
echo "Password:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";
echo "</FORM>\n";
exit;
}
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "deletepass") {
$data = file('news.txt');
//this next line will remove the single news item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item deleted!<BR><BR>\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
} else {
echo "Bad password!\n";
exit;
}
}
if($action == "delete") {
echo "<H2>You are about to delete the following news item.</H2>\n";
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";
echo "<BR><BR>\n";
echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>\n";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
echo "Password:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";
echo "</FORM>\n";
exit;
}
echo "<H1><u>Current News</u></H1>\n";
$data = file('news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";
echo " <a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";
echo " <a href=\"$PHP_SELF?action=edit&id=$key\">Edit</a>\n";
echo "<BR><BR>\n";
}
echo "<HR>\n";
echo "<H1><u>Add News</u></H1>\n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "<b>News added!</b>\n";
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
The News:<BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
News Password:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM>
if anyone can help I would appreciate it.
Parse error: parse error, unexpected T_STRING in d:\InetPub\wwwroot\wask\news.php on line 1
the full code for this page is below
<?
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "editpass") {
//First let's recompile that line with the pipe symbols so we can reinsert it
$line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
$data = file('news.txt');
$data[$id] = $line;
//the next line makes sure the $data array starts at the beginning
reset($data);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item Edited!<BR><BR>\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
} else {
echo "Bad password!\n";
exit;
}
}
if($action == "edit") {
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
//the next line is to reverse the process of turning the end of lines into breaking returns
$news = str_replace("<BR>","\r\n",$pieces[2]);
echo "Make the changes you would like and press save.<BR>\n";
echo "<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
echo "Name:<BR>\n";
echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
echo "The News:<BR>\n";
echo "<TEXTAREA NAME=\"news\" COLS=\"40\" ROWS=\"5\">".$news."</TEXTAREA><BR><BR>\n";
echo "Password:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";
echo "</FORM>\n";
exit;
}
if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
//obviously you should change this password on the next line
if($HTTP_POST_VARS['password'] == "deletepass") {
$data = file('news.txt');
//this next line will remove the single news item from the array
array_splice($data,$id,1);
//now we open the file with mode 'w' which truncates the file
$fp = fopen('news.txt','w');
foreach($data as $element) {
fwrite($fp, $element);
}
fclose($fp);
echo "Item deleted!<BR><BR>\n";
echo "<a href=\"$PHP_SELF\">Go Back</a>\n";
exit;
} else {
echo "Bad password!\n";
exit;
}
}
if($action == "delete") {
echo "<H2>You are about to delete the following news item.</H2>\n";
$data = file('news.txt');
$element = trim($data[$id]);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";
echo "<BR><BR>\n";
echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>\n";
echo "<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
echo "Password:<BR>\n";
echo "<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";
echo "</FORM>\n";
exit;
}
echo "<H1><u>Current News</u></H1>\n";
$data = file('news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
$element = trim($element);
$pieces = explode("|", $element);
echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>\n";
echo " <a href=\"$PHP_SELF?action=delete&id=$key\">Delete</a>\n";
echo " <a href=\"$PHP_SELF?action=edit&id=$key\">Edit</a>\n";
echo "<BR><BR>\n";
}
echo "<HR>\n";
echo "<H1><u>Add News</u></H1>\n";
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'pass') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","<BR>",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
echo "<b>News added!</b>\n";
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Your name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
The News:<BR>
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
News Password:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM>
if anyone can help I would appreciate it.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
sorry guys it is the full code. It is actually from a tutorial at http://codewalkers.com/tutorials.php?show=7&page=5 you will see all I have done is cut and paste.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
It's really weird that you get this error because cutting and pasting the same code I don't and parse errors aren't system specific (are they?). Are you sure you didn't accidentally type an extra character on the first line of your own version of this code?
I doubt it's the isset() or empty() functions causing issues, I've never seen them cause parse errors.
Mac
I doubt it's the isset() or empty() functions causing issues, I've never seen them cause parse errors.
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
OK, you've got a parse error when you run the code that nobody else can replicate when they run the same code. This (curtesy of dale) may help explain a bit more what causes a parse error: http://www.imahosting.com/dale/php/
What does the first line (after the <?php bit) of your version of the code that you are running to get this error look like?
Mac
What does the first line (after the <?php bit) of your version of the code that you are running to get this error look like?
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
What is your setup, ie. which version of PHP, which OS and which webserver. I know you're probably really frustrated with all of this but it's very difficult to help without being able to reproduce the error. One thing you might want to try (if you haven't already) is to copy and paste the code again into a new file and try and run that.
Sorry that we haven't been able to be of better help.
Mac
Sorry that we haven't been able to be of better help.
Mac
no its cool man thanks for the help. I am running on a windows nt server (not my choice its the clients!) I thought that maybe it was the problem but I have not scrapped that script and found another but im now getting an error
Notice: Undefined variable: title in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
Notice: Undefined variable: news in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
Notice: Undefined variable: author in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
the script is below but I cant find anything wrong with it? Or am I just crap?
<?
include "common.php";
$dbcon = mysql_connect("$server", "$user", "$password");
if (!$dbcon)
die("failed to open database");
if (!mysql_select_db ($db, $dbcon) )
{
die ("couldn't open $db: ".mysql_error() );
}
/* We have now connected, unless you got an error message */
/* Lets post some news ! */
$query = "INSERT INTO news(title, news, author, date) VALUES('$title','$news','$author', now())";
if (!mysql_query ($query, $dbcon) )
{
die (mysql_error());
}
echo ("News item entered.");
?>
Notice: Undefined variable: title in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
Notice: Undefined variable: news in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
Notice: Undefined variable: author in d:\InetPub\wwwroot\wask\post_news_process.php on line 19
the script is below but I cant find anything wrong with it? Or am I just crap?
<?
include "common.php";
$dbcon = mysql_connect("$server", "$user", "$password");
if (!$dbcon)
die("failed to open database");
if (!mysql_select_db ($db, $dbcon) )
{
die ("couldn't open $db: ".mysql_error() );
}
/* We have now connected, unless you got an error message */
/* Lets post some news ! */
$query = "INSERT INTO news(title, news, author, date) VALUES('$title','$news','$author', now())";
if (!mysql_query ($query, $dbcon) )
{
die (mysql_error());
}
echo ("News item entered.");
?>
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
If you are getting $title, $news and $author from a form try changing them to $_POST['title'], $_POST['news'] and $_POST['author']. Have a read of this as well:
http://www.devnetwork.net/forums/viewtopic.php?t=511
Try:
Hopefully this helps,
Mac
http://www.devnetwork.net/forums/viewtopic.php?t=511
Try:
Code: Select all
<?php
include "common.php";
$dbcon = mysql_connect($server, $user, $password) or die(mysql_error());
mysql_select_db ($db) or die ('couldn''t open '.$db.': '.mysql_error());
/* We have now connected, unless you got an error message */
/* Lets post some news ! */
$query = "INSERT INTO news(title, news, author, date) VALUES('".$_POSTї'title']."', '".$_POSTї'news']."', '".$_POSTї'author']."', now())";
mysql_query ($query) or die (mysql_error());
echo 'News item entered.';
?>Mac