PHP/MYSQL/HTML

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

PHP/MYSQL/HTML

Post by AlbinoJellyfish »

I want to input html code in a box, use post to send to mysql, then call it up and display what the page would look like if I had just used html. When I enter the code, the Html tags get removed... How do I keep them?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

show your code.
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Post by AlbinoJellyfish »

Code: Select all

<html>
<head><title>Add News</title></head>
<body>

<?php



$db = mysql_connect("localhost", "not tellin","not tellin");

mysql_select_db("announcements",$db);
  // query the DB

  $sql = "SELECT * FROM news";

  $result = mysql_query($sql);	

  $myrow = mysql_fetch_array($result);
  
  ?>

<form method="post" action="addnewsp.php">
  <input type=hidden name="id" value="<?php echo $id ?>">

  Date:<input type="Text" name="date" value=""><br>

  Description:<input type="Text" name="description" value=""><br>
  Story:
  <br><TEXTAREA NAME="story" ROWS="8" COLS="48">Type your story here</TEXTAREA> <br>
  Link to:<input type="Text" name="link" value=""><br>

  <input type="Submit" name="submit" value="Enter information">

  </form>
<?php
mysql_close($db);
?>
</body>
</html>
This is POST page:

Code: Select all

<html><head><title>Adding News</title></head>
<body>
<?
$id=$_POST['id'];
$date=$_POST['date'];
$description=$_POST['description'];
$story=$_POST['story'];
$link=$_POST['link'];
$db = mysql_connect("localhost","mattmooers","minnetonka");
mysql_select_db("announcements",$db);
if (! $db)
die("Couldn't connect to MySQL");
mysql_query(" INSERT INTO news (date,description,link,story) VALUES ('$date','$description','$link','$story')");
echo "News Added";
mysql_close($db);
?>
</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's the structure of the table news?

In your insertion page, add this:

Code: Select all

echo nl2br(htmlentities($story,ENT_QUOTES));
somewhere after $story is set.. and see if the data is posting correctly..
AlbinoJellyfish
Forum Commoner
Posts: 76
Joined: Sun Apr 04, 2004 7:39 pm

Post by AlbinoJellyfish »

Hmmm, now when it posts, it works...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

k.. so move on to looking directly into the database with whatever you have as an interface program for it.. if you have one..

next step beyond that is making sure the output has html in it.. with exactly the same echo I have above.. but getting the story from the database..

How are you accessing the data? Can I see that code?
Post Reply