Jump to content


Photo

TXT News Script Help


  • Please log in to reply
7 replies to this topic

#1 dylanburford

dylanburford
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 July 2006 - 07:49 PM

I am writing a simple news script for my site that writes a news HTML paragraph to a .txt file. But when i compile it (open it in a web browser) this is what i get:


Parse error: parse error, unexpected T_VARIABLE in C:\xampp\htdocs\Qwakhouse\Layout\admin\makenews.php on line 69

The Script:
<?php
/* For Username and Password */
$username = $_POST['username'];
$password = $_POST['passord'];

/* for posts */
$title = $_POST['title'];
$post = $_POST['post'];
$mainpost = $_POST['mainpost'];


/* Other */
$num = '1';

if(empty( $username ) || empty($post)) {
echo 'Username & Password are empty';
} else if(empty( $username )) {
echo 'Username is empty';
} else if(empty( $password )) {
echo 'Password is empty';
} else if( $username =='Josh' || $password =='tiki' ) {
domakenews();
} else if( $username =='Allen' || $password =='jedi' ) {
domakenews();
} else if( $username =='Dylan' || $password =='6483a66' ) {
domakenews();
} else {
echo 'Username or Password is empty';
}

if( $username =='Josh' ) {
$email =='blood_hoobit@hotmail.com';
} else if( $username =='Allen' ) {
$email =='coheed_and_cambria_awmjr@hotmail.com';
} else if( $username =='Dylan' ) {
$email =='dead_dylan665@hotmail.com';
}

if(empty( $post) || empty($mainpost) || empty($title) ) {
echo 'All Fields Are Empty';
} else if(empty( $post )) {
echo 'Intro News is Empty';
} else if(empty( $title )) {
echo 'Title is Empty';
}

function domakenews() {

if(empty( $mainpost )) {
dointronews();
} else {
dofullnews();
}

}

function dointronews() {
$file = fopen('news.txt', 'a');
fwrite($file, "
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post</p>
<hr />
" );
}

function dofullnews() {
$file = fopen('news.txt', 'a');
fwrite($file, "
$num = $num+1
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post | Read More...</p>
<?php
if( $pid =='102564456985214563256325632$num' ) {
?>
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post $mainpost</p>
<hr />
");
}
?>


#2 dptr1988

dptr1988
  • Members
  • PipPipPip
  • Advanced Member
  • 372 posts

Posted 14 July 2006 - 08:00 PM

It looks like you forgot to add the '<?php' tag at the begining of your script.

Need more help with your project? One of the thousands of programmers, web designers or artists at <a href="http://www.rentacode...d_6764522">Rent A Coder</a> would be happy to help.

Disclaimer: Free advice is usually worth what you paid for it. ( or at least when it's coming from me! )

#3 dylanburford

dylanburford
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 14 July 2006 - 08:11 PM

yeh but when i do that i get this error Parse error: parse error, unexpected T_VARIABLE in C:\xampp\htdocs\Qwakhouse\Layout\admin\makenews.php on line 69

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 July 2006 - 09:38 PM

your script/logic is a little quirky - are you trying to actually WRITE that PHP markup into the text file?

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 14 July 2006 - 09:48 PM

leave that at the top ok.

<?php

show us line errow ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 15 July 2006 - 01:07 AM

if( $pid =='102564456985214563256325632$num' ) {

Hmm.. You didn't close right ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 July 2006 - 01:17 AM

Either change your fwrite lines to be a single line rather than multiple:
fwrite($file, "
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post</p>
<hr />
" );
Should be:
fwrite($file, "<p><h3>$title</h3></p><h5>Posted By: $username</h5><p>$post</p><hr />" );

or assign the multiple lines to a variable then write that to your file.

You should be using fclose to close your files after you write to them.

In the second fwrite, the one that's a part of your dofullnews function, if you are intending to write the php code there and not the variables...i.e. have the text of your file be:

$num = $num+1
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post | Read More...</p>
<?php
if( $pid =='102564456985214563256325632$num' ) {
?>
<p><h3>$title</h3></p>
<h5>Posted By: $username</h5>
<p>$post $mainpost</p>
<hr />


Rather than substituting the values of variables for the variable names, then you need to use a single quote rather than double.

#8 dylanburford

dylanburford
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 15 July 2006 - 05:33 AM

so do it like
fwrite($file, '<html><head><title>Test</title></head></html>');
fclose();





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users