Page 1 of 1

[SOLVED] allowing html

Posted: Mon Dec 01, 2003 3:19 pm
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

Posted: Mon Dec 01, 2003 4:38 pm
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?

Posted: Mon Dec 01, 2003 4:51 pm
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

Posted: Mon Dec 01, 2003 4:55 pm
by mrvanjohnson
:D Funny, not a problem.. Happy PHPing

Posted: Mon Dec 01, 2003 4:56 pm
by RoMeRz
hehe cheers for the help tho :)

Posted: Mon Dec 01, 2003 8:26 pm
by dull1554
lol

Posted: Tue Dec 02, 2003 5:07 am
by RoMeRz
:P