Jump to content
xisto Community
alex1985

Alex's Trials. Find Mistakes?

Recommended Posts

Hi, I getting this mistake, I do not know why, the code itself looks fine and right:

Parse error: syntax error, unexpected $end in /home/alex1985/public_html/mulhim/library_project/test_dir/test1/admin/addbooks.php on line 12



<?phpinclude ("../config.php");if ($_GET['login']) { #checks for admin login$user=trim($_POST['user']); #trim the admin user in case of mistake$pass=trim($_POST['pass']);str_replace("username", "password", $srt);if ($user == "username" && $pass="password") { #if username and password match, then show posting formsession_register('username'); #starts an admin section onlyecho "Welcome, please post books' entries $user<br>Or: ";?><a href="editnews.php'>Edit News/Delete News</a>

Share this post


Link to post
Share on other sites

Uhm... you might wanna close your if-statement blocks with '}'

  $user=trim($_POST['user']); #trim the admin user in case of mistake
$pass=trim($_POST['pass']);
str_replace("username", "password", $srt);
if ($user == "username" && $pass="password") { #if username and password match, then show posting form
session_register('username'); #starts an admin section only
echo "Welcome, please post books' entries $user<br>Or linenums:0'><?phpinclude ("../config.php");if ($_GET['login']) { #checks for admin login $user=trim($_POST['user']); #trim the admin user in case of mistake $pass=trim($_POST['pass']); str_replace("username", "password", $srt); if ($user == "username" && $pass="password") { #if username and password match, then show posting form session_register('username'); #starts an admin section only echo "Welcome, please post books' entries $user<br>Or: ";<strong class='bbc'> }}</strong>?><a href="editnews.php'>Edit News/Delete News</a>

Share this post


Link to post
Share on other sites

Uhm... you might wanna close your if-statement blocks with '}'

  $user=trim($_POST['user']); #trim the admin user in case of mistake
$pass=trim($_POST['pass']);
str_replace("username", "password", $srt);
if ($user == "username" && $pass="password") { #if username and password match, then show posting form
session_register('username'); #starts an admin section only
echo "Welcome, please post books' entries $user<br>Or linenums:0'><?phpinclude ("../config.php");if ($_GET['login']) { #checks for admin login $user=trim($_POST['user']); #trim the admin user in case of mistake $pass=trim($_POST['pass']); str_replace("username", "password", $srt); if ($user == "username" && $pass="password") { #if username and password match, then show posting form session_register('username'); #starts an admin section only echo "Welcome, please post books' entries $user<br>Or: ";<strong class='bbc'> }}</strong>?><a href="editnews.php'>Edit News/Delete News</a>

I think Alex didn't write all the source codes. He only wrote the first 11 lines. Alex, can you write the first 20 lines or all the lines, so we can tell a good solution.

Share this post


Link to post
Share on other sites

I think Alex didn't write all the source codes. He only wrote the first 11 lines. Alex, can you write the first 20 lines or all the lines, so we can tell a good solution.

No, sometimes PHP reports the wrong line, even if it's non-existent, where the problem is else where. Salamangkero's suggestion should fix it.

Share this post


Link to post
Share on other sites

Actually in this case php is saying the right line. Its telling you that it didn't expect the end of the file to be on line 12 with two if statements still open. Like truefusion said however, Salamangkero's solution should work.

Share this post


Link to post
Share on other sites

All right. What's about this code:

<?phpinclude("config.php");if($submit){$title=$_POST['title'];$text1=$_POST['text1'];$text2=$_POST['text2'];if($title) {echo "Error: News title is a required field. Please fill it.";exit();}$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',NOW(),'$text1','$text2')",$connect);echo "<b>Thank You! The book was added successfuly!<br>You'll be redirected to Home Page after (4) seconds";echo "<meta http-equiv=Refresh content=4;url=index.php>";}else{?><br><h3>Add Books</h3><form method="post" action="?php echo $PHP_SELF ?>">Title: <input name="title" size="40" maxlength="255"><br>Text2: <textarea name="text2" rows="7" cols="30"></textarea><br><input type="submit" name="submit" value="Add News"></form><?}?>

Your suggestions of correct and improvement is neeeded

Share this post


Link to post
Share on other sites

All right. What's about this code:

$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',NOW(),'$text1','$text2')",$connect);
I think using time() is better than NOW()
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',time(),'$text1','$text2')",$connect);
--------------------

<form method="post" action="?php echo $PHP_SELF ?>">
Here there is an error
<form method="post" action="<?php echo $_PHP_SELF ?>">

And also I would use only
<? echo($_PHP_SELF); ?>
, I think this is shorter.

 

//Edit

I tried this

<? echo($_PHP_SELF); ?>
and did not work, because of wrong or my php version.

But this

<? echo($_SERVER["PHP_SELF"]); ?>
worked properly and wrote the file path+name .

 

I think you should use $_SERVER["PHP_SELF"]

Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

I think using time() is better than NOW()

Actually time isn't an sql function, its a function in php while now is an sql function. If you wanted to use time you'd have to put it outside of the quotes. PHP isn't going to parse that inside the quotes.example:
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',".time().",'$text1','$text2')",$connect);

I suggest you use NOW if you wanted to let sql handle the time... or, you could use current_timestamp.
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',CURRENT_TIMESTAMP(),'$text1','$text2')",$connect);
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',NOW(),'$text1','$text2')",$connect);

Edited by galexcd (see edit history)

Share this post


Link to post
Share on other sites

Actually time isn't an sql function

Sorry, I wanted to write as
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',".time().",'$text1','$text2')",$connect);

Share this post


Link to post
Share on other sites

Please, check the following one:

<?phpinclude("../config.php");if($submit){$title = $_POST['title'];$short = $_POST['short'];$full = $_POST['full'];if(!$title){echo "Error: The book's title is reguired field. Please, fill it.";exit();}$result = mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES ('$title',NOW(),'$text1','$text2')",$connect);echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";echo "<meta http-equiv=Refresh content=4;url=index.php>";}else{?><br><h3>Add Books</h3><form method="post" action="<?php echo $PHP_SELF ?>">Title: <input name="title" size="40" maxlength="255"><br>Text1: <textarea name="text1" rows="7" cols="30"></textarea><br>Text2: <textarea name="text2" rows="7" cols="30"></textarea><br><input type="submit" name="submit" value="Add News"></form><?}//end of else?>

Share this post


Link to post
Share on other sites

//Edit

I tried this

<? echo($_PHP_SELF); ?>
and did not work, because of wrong or my php version.

But this

<? echo($_SERVER["PHP_SELF"]); ?>
worked properly and wrote the file path+name .

 

I think you should use $_SERVER["PHP_SELF"]

Did you remember what I have written about $PHP_SELF and $_PHP_SELF?

 

Quite useful replies, thanks

So you found $_SERVER["PHP_SELF"] is useful.

 

<form method="post" action="<?php echo $PHP_SELF ?>">
Here you wrote $PHP_SELF again. I said this is not working, but you are still using. My analysis are the same with the previous again.

So you don't agree with my suggestions or you are kidding, right?

 

Regards...

Share this post


Link to post
Share on other sites

Listen, this code thing does work. It does not update the database at all, what's the problem?

Than sorry me, so the problem is about updating the database.

 

But there is no update database code you specified. There is only insert database code.

mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES ('$title',NOW(),'$text1','$text2')",$connect);
If there is a problem it must be about insert.

 

By the way $text1 and $text2 are undefined in previous lines, they are not defined.

Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.