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? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 anyone? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 14, 2006 Author Share Posted August 14, 2006 ...................... Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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] Quote Link to comment 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? Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Prismatic Posted August 14, 2006 Share Posted August 14, 2006 Oops, sorry about that :-\ Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment 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')); Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 i stil cant get it working! Quote Link to comment 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] Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
trq Posted August 15, 2006 Share Posted August 15, 2006 There is no form! Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 anyone? Quote Link to comment Share on other sites More sharing options...
onthespot Posted August 15, 2006 Author Share Posted August 15, 2006 ???? Quote Link to comment 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.