Jump to content


Photo

news php


  • Please log in to reply
23 replies to this topic

#1 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 09:33 PM

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

#2 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 09:50 PM

anyone?

#3 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 10:04 PM

......................

#4 Buddyb3ar

Buddyb3ar
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 August 2006 - 10:12 PM

When you echo something that's not a variable, it should be within quotes... right?

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;";

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

#5 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 10:38 PM

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?

#6 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 14 August 2006 - 10:46 PM

Give this a try

<?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;";
}
?>


#7 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 11:42 PM

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?

#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 August 2006 - 11:43 PM

Its a parse error, pretty simple stuff....

echo $news['text'] ."..&quot;&lt;br&gt;n&quot;;";


#9 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 14 August 2006 - 11:47 PM

Oops, sorry about that  :-\

#10 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 14 August 2006 - 11:55 PM

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!

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 August 2006 - 11:59 PM

These are parse errors. Simple mistakes. You really need to learn to fix these yourself.

can someone correct is please!


Maybe if you posted the code.... but as I said, you really need to learn to fix these yourself.

#12 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 12:02 AM

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'));

#13 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 12:13 AM

i stil cant get it working!

#14 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 August 2006 - 12:15 AM

mysql_query expects a string.

mysql_query("INSERT INTO news (title,text) VALUES ('$title','$text')");

edit: ps... your still going to have problems with that because text is a reserved word in sql. Try...

mysql_query("INSERT INTO news (title,`text`) VALUES ('$title','$text')");


#15 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 12:17 AM

thankyou mate, that just taught me something!

#16 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 12:22 AM


<?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')"); ?>

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?

#17 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 August 2006 - 12:24 AM

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?

#18 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 August 2006 - 12:28 AM

Also... where do you define $title and $text?

#19 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 12:33 AM

ive missed something out somewhere, there is nowhere to type the news in!

#20 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 August 2006 - 12:34 AM

There is no form!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users