Snitz
03-29-2007, 04:27 AM
How can I include the <br> whenever someone writes something in a textarea field and has many <br> in it?
I did it and its showing it as a 1 line!
I have only 2 files
this is index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Thoughts</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="527" bgcolor="#CCCCCC"> 
<form action="insert_db.php" method="POST">
<label>
<div align="center">
<p>
<textarea name="quote" cols="50" rows="20"></textarea>
<br />
<br />
name:
<input type="text" name="name" />
<br />
<br />
email:
<input type="text" name="email" />
<br />
</p>
</div>
</label>
<div align="center">
<input type="submit" value="Submit" />
</div>
</form>;</td>
<td width="500" bgcolor="#666666"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><div align="center"><font color="#FFFFFF"><h1>Latest Submissions</h1></font></div></td>
</tr>
<tr>
<td valign="middle"><div align="center">
<?php
$mysqli = mysqli_connect("localhost", "root", "", "blackquote");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "SELECT * FROM data ORDER BY id desc LIMIT 5";
$res = mysqli_query($mysqli, $sql);
if ($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$id = $newArray['id'];
$quote = $newArray['quote'];
$email = $newArray['email'];
$name = $newArray['name']; ?>
<?php echo"".$quote."" ?> - <i>By <a href="mailto:<?php echo "".$email."" ?>"><?php echo "".$name."" ?></a></i><br />
Quote #<?php echo "".$id."" ?><br />
<br />
<?php
// echo"".$quote." - <i>By ".$name."</i><br />Thought #".$id."<br/><br />";
}
} else {
printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
}
mysqli_free_result($res);
mysqli_close($mysqli);
}
?>
</div></td>
</tr>
<tr>
<td valign="bottom"><div align="center">
<?php
$link = mysql_connect("localhost", "root", "");
mysql_select_db("blackquote", $link);
$result = mysql_query("SELECT * FROM data", $link);
$num_rows = mysql_num_rows($result);
?>
<div align="center">
<span class="style3">Now Serving</span>
<INPUT
style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; FONT-FAMILY: verdana; TEXT-ALIGN: center"
onfocus=this.blur() size=11 value="<?php echo "$num_rows"; ?>">
</div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
and this is insert_db.php
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("blackquote", $con);
$sql="INSERT INTO data
(quote,name,email)
VALUES
('$_POST[quote]','$_POST[name]','$_POST[email]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("location: redirect.php");
exit();
?>
if you could fix me the errors i've done, i'd be thankful!
I did it and its showing it as a 1 line!
I have only 2 files
this is index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Thoughts</title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="527" bgcolor="#CCCCCC"> 
<form action="insert_db.php" method="POST">
<label>
<div align="center">
<p>
<textarea name="quote" cols="50" rows="20"></textarea>
<br />
<br />
name:
<input type="text" name="name" />
<br />
<br />
email:
<input type="text" name="email" />
<br />
</p>
</div>
</label>
<div align="center">
<input type="submit" value="Submit" />
</div>
</form>;</td>
<td width="500" bgcolor="#666666"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><div align="center"><font color="#FFFFFF"><h1>Latest Submissions</h1></font></div></td>
</tr>
<tr>
<td valign="middle"><div align="center">
<?php
$mysqli = mysqli_connect("localhost", "root", "", "blackquote");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "SELECT * FROM data ORDER BY id desc LIMIT 5";
$res = mysqli_query($mysqli, $sql);
if ($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$id = $newArray['id'];
$quote = $newArray['quote'];
$email = $newArray['email'];
$name = $newArray['name']; ?>
<?php echo"".$quote."" ?> - <i>By <a href="mailto:<?php echo "".$email."" ?>"><?php echo "".$name."" ?></a></i><br />
Quote #<?php echo "".$id."" ?><br />
<br />
<?php
// echo"".$quote." - <i>By ".$name."</i><br />Thought #".$id."<br/><br />";
}
} else {
printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
}
mysqli_free_result($res);
mysqli_close($mysqli);
}
?>
</div></td>
</tr>
<tr>
<td valign="bottom"><div align="center">
<?php
$link = mysql_connect("localhost", "root", "");
mysql_select_db("blackquote", $link);
$result = mysql_query("SELECT * FROM data", $link);
$num_rows = mysql_num_rows($result);
?>
<div align="center">
<span class="style3">Now Serving</span>
<INPUT
style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; FONT-FAMILY: verdana; TEXT-ALIGN: center"
onfocus=this.blur() size=11 value="<?php echo "$num_rows"; ?>">
</div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
and this is insert_db.php
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("blackquote", $con);
$sql="INSERT INTO data
(quote,name,email)
VALUES
('$_POST[quote]','$_POST[name]','$_POST[email]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header("location: redirect.php");
exit();
?>
if you could fix me the errors i've done, i'd be thankful!
