Jump to content

Archived

This topic is now archived and is closed to further replies.

onthespot

news php

Recommended Posts

  <?
  mysql_connect
('host','un','pw');
// login into the mysql database server
mysql_select_db('dbname');
// select the site's database
$query = mysql_query
('SELECT * FROM news');
// get all the news in the 'news' table
while($news = mysql_fetch_array
($query)) {
echo &quot;Title: &quot;. $news['title'] . &quot;&lt;br&gt;n&quot;;
echo $news['text'] .&quot;&lt;br&gt;n&quot;; 
echo &lt;&quot;---------------------n&quot;
; } ?>


that is the code i have however, im getting an error
Parse error: parse error, unexpected ':', expecting ',' or ';'

can anyone spot anything wrong?

Share this post


Link to post
Share on other sites
When you echo something that's not a variable, it should be within quotes... right?

[code]
echo "&quot;Title: &quot;. $news['title'] . &quot;&lt;br&gt;n&quot;";
echo "$news['text'] .&quot;&lt;br&gt;n&quot;"; 
echo "&lt;&quot;---------------------n&quot;";
[/code]

So, if it shouldn't be in quotes if it's something like
[code]
$code = "&quot;Title: &quot;. $news['title'] . &quot;&lt;br&gt;n&quot;";
print $code;
[/code]
[b]Edit[/b] Print/echo same thing. Haha. I just choose print over echo.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Give this a try

[code]
<?php
// login into the mysql database server
mysql_connect('host','un','pw');
// select the site's database
mysql_select_db('dbname');
// get all the news in the 'news' table
$query = mysql_query('SELECT * FROM news');

while($news = mysql_fetch_array($query)){
echo "&quot;Title: &quot;. ".$news['title']." . &quot;&lt;br&gt;n&quot;;";
echo $news['text'] "..&quot;&lt;br&gt;n&quot;;";
echo "&lt;&quot;---------------------n&quot;";
}
?>
[/code]

Share this post


Link to post
Share on other sites
on the line
echo $news['text'] "..&quot;&lt;br&gt;n&quot;;";
im getting
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'

any ideas?

Share this post


Link to post
Share on other sites
Its a parse error, pretty simple stuff....

[code=php:0]
echo $news['text'] ."..&quot;&lt;br&gt;n&quot;;";
[/code]

Share this post


Link to post
Share on other sites
mysql_query(INSERT INTO news (title,text) VALUES ('$title','$text'));

that is the final line of my code

im getting this error, im not great at php, still learning!

Parse error: parse error, unexpected T_STRING

can someone correct is please!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
so all parse errors are simple? ill take ur advice then chap and try myself! BTW
the code was
mysql_query(INSERT INTO news (title,text) VALUES ('$title','$text'));

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

[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'] ."..&quot;&lt;br&gt;n&quot;;"; ?>
echo "&lt;&quot;---------------------n&quot;";
<?
}
?>

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Also... where do you define $title and $text?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.