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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.