[SOLVED] allowing html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RoMeRz
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2003 3:19 pm
Location: Scotland

[SOLVED] allowing html

Post by RoMeRz »

postnews.php (just takes info from standard forms and puts them into the mysql database)

Code: Select all

<?PHP 
$db = mysql_connect("localhost","******","******");
mysql_select_db ("******") or die ("Cannot connect to database");
$query = "INSERT INTO news(title, news, author, date)
VALUES('".$_POST['title']."','".$_POST['news']."','".$_POST['author']."', now())";
mysql_query($query);
echo "News Item Entered.";
mysql_close($db);
?>
view.php (shows the data from the mysql db)

Code: Select all

<?php

$db = mysql_connect("localhost","******","******");
mysql_select_db ("******") or die ("Cannot connect to database");

#set the sql command as a variable
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 10";

#set the results
$result = mysql_query($query);

#take the results and echo them on the page as html for each returned record
while($r=mysql_fetch_array($result))
{  
   $title=$r["title"];
   $news=$r["news"];
   $author=$r["author"];
   $date=$r["date"];   

      print "
	  <table width="200" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td class="style2 style1">News: $title</td>
  </tr>
  <tr>
    <td class="style2 style1"><p>$news</p>
    <p>Posted by: $author at $date</p></td>
  </tr>
</table>
</br>";
			  
}


#close the connection
mysql_close($db);

?>
what im wanting it to do is when i say add in <img src="images/image.gif">

it will add in the image. same goes for links etc.

any ideas, ta
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Nothing in your code is showing that it wouldn't do that. If you entered <a href="http://www.somewhere.com" Web Link </a> then this is what should show up when you call the data Web Link

If you where doing something like [php_man]htmlspecialchars[/php_man] then PHP would encode the HTML and you would get back what you put in (<a href="http://www.somewhere.com" Web Link </a> ). But looking at your code you don't seem to be doing that anywhere. So what is the problem? Is it not working correctly?
RoMeRz
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2003 3:19 pm
Location: Scotland

Post by RoMeRz »

yeah, i just relised this. See i never actually tested this - instead i went searchin on the web - and like nowadays its hard to find much info sinse everything is trying to sell you something. but yeah it already works rofl, sorry for time waste
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

:D Funny, not a problem.. Happy PHPing
RoMeRz
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2003 3:19 pm
Location: Scotland

Post by RoMeRz »

hehe cheers for the help tho :)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

lol
RoMeRz
Forum Newbie
Posts: 7
Joined: Mon Dec 01, 2003 3:19 pm
Location: Scotland

Post by RoMeRz »

:P
Post Reply