Alex's Trials. - Find Mistakes?

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #15) by alex1985 on Jun 17 2008, 05:14 PM. (Line Breaks Removed)
Thanks. I should change those variable and try it again.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Alex's Trials. - Find Mistakes?

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

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


CODE
<?php
include ("../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: ";
?>
<a href="editnews.php'>Edit News/Delete News</a>

 

 

 


Reply

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

CODE
<?php
include ("../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: ";
}
}

?>
<a href="editnews.php'>Edit News/Delete News</a>

Reply

Erdemir
QUOTE(salamangkero @ Jun 12 2008, 01:13 PM) *
Uhm... you might wanna close your if-statement blocks with '}'

CODE
<?php
include ("../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: ";
}
}

?>
<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.

 

 

 


Reply

truefusion
QUOTE(Erdemir @ Jun 12 2008, 06:47 AM) *
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.

Reply

galexcd
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.

Reply

alex1985
All right. What's about this code:

CODE
<?php
include("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

Reply

Erdemir
QUOTE(alex1985 @ Jun 12 2008, 09:29 PM) *
All right. What's about this code:


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()
CODE
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',time(),'$text1','$text2')",$connect);

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


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

//Edit
I tried this
CODE
<? echo($_PHP_SELF); ?>
and did not work, because of wrong or my php version.
But this
CODE
<? echo($_SERVER["PHP_SELF"]); ?>
worked properly and wrote the file path+name .

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

Reply

galexcd
QUOTE(Erdemir @ Jun 12 2008, 11:37 AM) *
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:
CODE
$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.
CODE
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',CURRENT_TIMESTAMP(),'$text1','$text2')",$connect);

CODE
$result=mysql_query("INSERT INTO books (title, dtime, text1, text2) VALUES('$title',NOW(),'$text1','$text2')",$connect);


Reply

Erdemir
QUOTE(galexcd @ Jun 13 2008, 12:09 AM) *
Actually time isn't an sql function


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

Reply

alex1985
Thanks. I think I am going to try it soon and then post a reply concerning such issues.

Reply

Latest Entries

alex1985
Thanks. I should change those variable and try it again.

Reply

Erdemir
QUOTE(alex1985 @ Jun 17 2008, 07:47 PM) *
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.
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.

Reply

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

Reply

Erdemir
QUOTE(Erdemir @ Jun 12 2008, 10:37 PM) *
//Edit
I tried this
CODE
<? echo($_PHP_SELF); ?>
and did not work, because of wrong or my php version.
But this
CODE
<? 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?

QUOTE(alex1985 @ Jun 17 2008, 06:59 PM) *
Quite useful replies, thanks

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

QUOTE(alex1985 @ Jun 17 2008, 07:24 PM) *
CODE
<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...

Reply

alex1985
Please, check the following one:

CODE
<?php
include("../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

?>

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. alex erdemir - 152.07 hr back. (2)
Similar Topics

Keywords : alexs trials mistakes


    Looking for alexs, trials, mistakes,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for alexs, trials, mistakes,

*MORE FROM TRAP17.COM*
advertisement



Alex's Trials. - Find Mistakes?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE