kyme Posted October 3, 2008 Share Posted October 3, 2008 guys i need ur help, i have jst practicing my php about w/ mySql.. Now my codes have no errors but i dnt understand my output.. config.php <?php //Change root to your database account's username $dbusername = "root"; //Add your account's password in between the quotations $password = " "; //Add the name of the database you are using in between the quotations $database = " "; //This usually does not need to be changed. $server = "localhost"; //Do not edit coding below this line. mysql_connect($server, $dbusername, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); ?> add.php <HTML> <form action="<? $_SERVER['PHP_SELF']; ?>" method="POST"> Author: <input type='text' size='30' name='author'><br><br> Subject: <input type='text' size='30' name='subject'><br><br> Message: <textarea name='message' rows='5' cols='30'></textarea><br><br> Date: <input type='text' size='30' name='date'><br>br> <input type='submit' name='submit' value='Add News'></form> <?php //Include the database file require_once('config.php'); //If the submit button is pressed if(isset($_POST['submit'])){ //Turn the inputs from the form into variables for insertion $author = $_POST['author']; $subject = $_POST['subject']; $message = $_POST['message']; $date = $_POST['date']; //Begin the database query $insert = mysql_query("INSERT INTO news(newsAuthor,newsSubject,newsMessage,newsDate) values('$author', '$subject', '$message', '$date')"); //Echo a message if the news was added echo "The news was successfully inserted into the database."; } ?> news.php </php require_once('config.php'); //The following bit of code will select the news and order the articles by their id, so if you post an article, the same article will show up at the top of the list. $query = mysql_query("SELECT * FROM news order by newsID desc"); while($n=mysql_fetch_array($query)){ $author=$n["newsAuthor"]; $subject=$n["newsSubject"]; $message=$n["message"]; $date=$n["date"]; echo "<b>$subject<br>$message<br>Posted by $author on $date"; } ?> Now i already created my database using phpmyadmin, but whats the problem? it appears on this after i submit Is there anything that i mess? Forbidden You don't have permission to access /Practice/< on this server. Pls. help me i really want to know.. Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/ Share on other sites More sharing options...
mysqldba Posted October 3, 2008 Share Posted October 3, 2008 In add.php, line 2: <form action="<? $_SERVER['PHP_SELF']; ?>" method="POST"> The use of short form of PHP opening tags is deprecated, and has been removed entirely from the latest PHP versions IIRC. Try: <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST"> Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-656414 Share on other sites More sharing options...
mysqldba Posted October 3, 2008 Share Posted October 3, 2008 Oh, and the opening tag on line 1 of news.php doesn't look right, either Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-656415 Share on other sites More sharing options...
kyme Posted October 17, 2008 Author Share Posted October 17, 2008 hey man wow thanks. it really it work..!! this forum could really give me a job! Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-667901 Share on other sites More sharing options...
kyme Posted October 20, 2008 Author Share Posted October 20, 2008 Guys now im done in saving into the database and now my problem is, i want to display it the data save it from the db. Is there something missing in my code at news.php? <?php require_once('config.php'); //The following bit of code will select the news and order the articles by their id, so if you post an article, the same article will show up at the top of the list. $query = mysql_query("SELECT * FROM news order by newsID desc"); while($n=mysql_fetch_array($query)){ $author=$n["newsAuthor"]; $subject=$n["newsSubject"]; $message=$n["message"]; $date=$n["date"]; echo "<b>$subject<br>$message<br>Posted by $author on $date"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-669859 Share on other sites More sharing options...
Flames Posted October 20, 2008 Share Posted October 20, 2008 theres other ways of doing it but i usually prefer using the heredoc syntax, you can find out more about it on the php site. change this line echo "<b>$subject<br>$message<br>Posted by $author on $date"; to this line echo <<<EOT <b[color=red]r[/color]>$subject<br>$message<br>Posted by $author on $date EOT; Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-669870 Share on other sites More sharing options...
Flames Posted October 20, 2008 Share Posted October 20, 2008 note i didnt realise ignore the r bit Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-669902 Share on other sites More sharing options...
kyme Posted October 20, 2008 Author Share Posted October 20, 2008 still wont work & it display into this Parse error: syntax error, unexpected T_SL in C:\wamp\www\Practice\news.php on line 14 Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-669909 Share on other sites More sharing options...
Flames Posted October 20, 2008 Share Posted October 20, 2008 that might mean multiple things either a missing } or ;. but it also could be coming from the heredoc syntax. you cant have anything other than echo <<<EOT on one line (no spaces), the stuff has to be on the next line, and similarly with EOT; it has to be on a seperate line with nothing else on that line. Check for any extra spaces. Quote Link to comment https://forums.phpfreaks.com/topic/126873-solved-help-me-about-php-output-practicing-mysql/#findComment-669948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.