alex1985
Jun 12 2008, 08:51 AM
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
Jun 12 2008, 10:13 AM
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
Jun 12 2008, 10:47 AM
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
Jun 12 2008, 11:39 AM
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
Jun 12 2008, 03:49 PM
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
Jun 12 2008, 06:29 PM
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
Jun 12 2008, 07:37 PM
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. //EditI 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
Jun 12 2008, 09:09 PM
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
Jun 12 2008, 09:14 PM
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
Jun 14 2008, 04:47 PM
Thanks. I think I am going to try it soon and then post a reply concerning such issues.
Reply
alex1985
Jun 17 2008, 05:14 PM
Thanks. I should change those variable and try it again.
Reply
Erdemir
Jun 17 2008, 04:58 PM
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
Jun 17 2008, 04:47 PM
Listen, this code thing does work. It does not update the database at all, what's the problem?
Reply
Erdemir
Jun 17 2008, 04:42 PM
QUOTE(Erdemir @ Jun 12 2008, 10:37 PM)  //EditI 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
Jun 17 2008, 04:24 PM
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
Recent Queries:--
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
|
|