onthespot Posted August 14, 2006 Share Posted August 14, 2006 <? mysql_connect('host','un','pw');// login into the mysql database servermysql_select_db('dbname');// select the site's database$query = mysql_query('SELECT * FROM news');// get all the news in the 'news' tablewhile($news = mysql_fetch_array($query)) {echo "Title: ". $news['title'] . "<br>n"; echo $news['text'] ."<br>n"; echo <"---------------------n"; } ?>that is the code i have however, im getting an error Parse error: parse error, unexpected ':', expecting ',' or ';' can anyone spot anything wrong? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/ Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74781 Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 ...................... Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74786 Share on other sites More sharing options...
Buddyb3ar Posted August 14, 2006 Share Posted August 14, 2006 When you echo something that's not a variable, it should be within quotes... right? [code]echo ""Title: ". $news['title'] . "<br>n""; echo "$news['text'] ."<br>n""; echo "<"---------------------n"";[/code]So, if it shouldn't be in quotes if it's something like [code]$code = ""Title: ". $news['title'] . "<br>n""; print $code; [/code][b]Edit[/b] Print/echo same thing. Haha. I just choose print over echo. Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74787 Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 still isnt working, could anyone send me in the correct direction of a tutorial?or supply me with the code to see the news on a page, and let an admin post news? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74795 Share on other sites More sharing options...
Prismatic Posted August 14, 2006 Share Posted August 14, 2006 Give this a try[code]<?php// login into the mysql database servermysql_connect('host','un','pw');// select the site's databasemysql_select_db('dbname');// get all the news in the 'news' table$query = mysql_query('SELECT * FROM news');while($news = mysql_fetch_array($query)){ echo ""Title: ". ".$news['title']." . "<br>n";"; echo $news['text'] ".."<br>n";"; echo "<"---------------------n"";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74800 Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 on the line echo $news['text'] ".."<br>n";";im gettingParse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' any ideas? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74816 Share on other sites More sharing options...
trq Posted August 14, 2006 Share Posted August 14, 2006 Its a parse error, pretty simple stuff....[code=php:0]echo $news['text'] .".."<br>n";";[/code] Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74818 Share on other sites More sharing options...
Prismatic Posted August 14, 2006 Share Posted August 14, 2006 Oops, sorry about that :-\ Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74821 Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 mysql_query(INSERT INTO news (title,text) VALUES ('$title','$text'));that is the final line of my codeim getting this error, im not great at php, still learning!Parse error: parse error, unexpected T_STRINGcan someone correct is please! Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74825 Share on other sites More sharing options...
trq Posted August 14, 2006 Share Posted August 14, 2006 These are parse errors. Simple mistakes. You really need to learn to fix these yourself.[quote]can someone correct is please![/quote]Maybe if you posted the code.... but as I said, you really need to learn to fix these yourself. Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74831 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 so all parse errors are simple? ill take ur advice then chap and try myself! BTW the code wasmysql_query(INSERT INTO news (title,text) VALUES ('$title','$text')); Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74833 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 i stil cant get it working! Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74839 Share on other sites More sharing options...
trq Posted August 15, 2006 Share Posted August 15, 2006 mysql_query expects a string.[code=php:0]mysql_query("INSERT INTO news (title,text) VALUES ('$title','$text')");[/code]edit: ps... your still going to have problems with that because [i]text[/i] is a reserved word in sql. Try...[code=php:0]mysql_query("INSERT INTO news (title,`text`) VALUES ('$title','$text')");[/code] Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74840 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 thankyou mate, that just taught me something! Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74842 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 [code]<?php(REMOVED THE CONNECTION)// get all the news in the 'news' table$query = mysql_query('SELECT * FROM news');while($news = mysql_fetch_array($query)){ ?> <br><? echo "Title:".$news['title'].""; ?><br> <? echo $news['text'] .".."<br>n";"; ?> echo "<"---------------------n"";<?}?><? (REMOVED THE CONNECTION)if(empty($title) || empty($text)) exit("You didn't completely fill in the form!");// $title = addslashes($title);$text = addslashes($text);// mysql_query("INSERT INTO news (title,text) VALUES ('$title','$text')"); ?>[/code]thats my code so far mate, its designed to show news and in the second part submit news! any ideas why its not doing what i want it to? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74849 Share on other sites More sharing options...
trq Posted August 15, 2006 Share Posted August 15, 2006 More than likely because your trying to use short tags <? as apposed to <?php but really, I wouldn't know. What is it not doing? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74850 Share on other sites More sharing options...
trq Posted August 15, 2006 Share Posted August 15, 2006 Also... where do you define $title and $text? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74853 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 ive missed something out somewhere, there is nowhere to type the news in! Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74856 Share on other sites More sharing options...
trq Posted August 15, 2006 Share Posted August 15, 2006 There is no form! Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74858 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 lol my script is all over the show, what do i need to add? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74860 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 can anyone re right this script to make it a form that i submit to add news to a page? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-75376 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-75387 Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 ???? Link to comment https://forums.phpfreaks.com/topic/17555-news-php/#findComment-75415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.