Jump to content

news php


onthespot

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?
Link to comment
https://forums.phpfreaks.com/topic/17555-news-php/
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.
Link to comment
https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74787
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]
Link to comment
https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74800
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]
Link to comment
https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74840
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?
Link to comment
https://forums.phpfreaks.com/topic/17555-news-php/#findComment-74849
Share on other sites

Archived

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

×
×
  • Create New...

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.