Help Needed With Text Area Script

mylifestyle

New Member
Messages
117
Reaction score
0
Points
0
Hi.

I am currently building a classified ad site and when the 'Description' is entered into the
'textarea' there are no line breaks or paragraphs showing.

ie: looks like :-

xxxx xxxx xxxx xxxx xxxx xxxx xxxx
xxxx xxxx xxxx xxxx xxxx xxxx xxxx
xxxx xxxx xxxx xxxx xxxx xxxx xxxx

I'd like to be able to have the members text read the same as they are inserting which includes line breaks and paragraps as they type them......

xxxx xxxx

xxxx xxxx xxxx xxxx xxxx xxxx xxxx
xxxx xxxx xxxx

xxxxx
xxxx

xxxxxxxxxxx

Does this make sense ?????

The code is below if you can help and I've highlighted the text area...

<?
if ($thisprimecat == "error") {
header("Location: placead.php");
}
else {
$thisprimecat = $_POST["thisprimecat"];
}
include("header.php");
include("linkfunctions.php");
if ( $_POST['B2'] ){
if ( !$_POST['ad_name'] )
$error[] = "You must enter your name!";

if ( !$_POST['ad_email'] )
$error[] = "You must enter an email address!";
elseif ( !preg_match("/^^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]+$$/i", $_POST['ad_email']) )
$error[] = "Invalid email address!";
if ( $_POST['thissubcat'] == "error")
$error[] = "Please select Sub Category!";
if ( !$_POST['ad_item'] )
$error[] = "You must enter your Item!";
if ( !trim($_POST['ad_price']) )
$error[] = "You must enter your Price or type 'FREE' or 'NA'!";
if ( !$_POST['ad_info'] )
$error[] = "You must describe your item!";
$thisprimecat = $_POST["thisprimecat"];
include("database.php");
//--------------------
if ( count($error) == 0 ){
$ad_price = ltrim($_POST['ad_price'], '$');
$ad_ticket = rand(10000,99999999);
if (!mysql_query("INSERT INTO site_ads VALUES (NULL, '".$ad_ticket."', '".$_POST['thisprimecat']."', '".$_POST['thissubcat']."', '".$_POST['ad_name']."', '".$_POST['ad_email']."', '".$_POST['ad_item']."', '".$ad_price."', '".$_POST['ad_info']."', '', 'n', 'n', 'n', NOW())") )
die("Error inserting data into database: ".mysql_error());

$ad_name = $_POST['ad_name'];
$ad_email = $_POST['ad_email'];
showpage($ad_ticket,$ad_name,$ad_email); die();


}//End if (count($error) == 0 ) - from validating email address and password
}
?>
<!-- header ends and body begins-->
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="801" background="images/backgrd.jpg">
<tr>
<td width="184" valign="top">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100">
<tr>
<td><font size="1">&nbsp;</font></td>
</tr>
</table>
</center>
</div>
<div align="right">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="159">
<?
GetPrimeCat($thislink);
?>
<tr>
<td width="159" class="primelink">&nbsp;</td>
</tr>
<tr>
<td width="159" class="primelink" align="center">
<?
include("common/adpanel3.php");
?>
</td>
</tr>
<tr>
<td width="159" class="primelink">&nbsp;</td>
</tr>
</table>
</div>
<p>&nbsp;</p>
</td>
<td width="617" valign="top">
<?
include("selectfunctions.php");
?>
<!-- main body begins here -->
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="458" height="117">
<tr>
<td width="458" height="24" class="adtitle">&nbsp;</td>
</tr>
<tr>
<td width="458" height="29" class="adtitle" valign="top"><img border="0" src="images/mpoint.gif" align="absmiddle"> Place an Ad <img border="0" src="images/bpoint.gif" align="absmiddle"> Step Two</td>
</tr>
<tr>
<td width="458" height="19">
<form method="POST" action="steptwo.php">
<div align="left">
<table border="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="380">
<tr>
<td width="143" align="right" class="primelink"></td>
<td width="257" class="booboo">
<?php if ( count($error) > 0 ){
$msg = join("<br>", $error);
print "$msg";
}
?>
</td>
</tr>
<tr>
<td width="143" align="right" class="primelink">Name:</td>
<td width="257">
<input type="text" name="ad_name" size="50" value="<?=$_POST['ad_name'];?>" style="font-size: 9pt; color: #000080"></td>
</tr>
<tr>
<td width="123" align="right" class="primelink">Email:</td>
<td width="257"><input type="text" name="ad_email" size="50" value="<?=$_POST['ad_email'];?>" style="font-size: 9pt; color: #000080"></td>
</tr>
<tr>
<td width="123" align="right" class="primelink">Item:</td>
<td width="257"><input type="text" name="ad_item" size="50" value="<?=$_POST['ad_item'];?>" style="font-size: 9pt; color: #000080"></td>
</tr>
<tr>
<td width="123" align="right" class="primelink">Sub-Cat:</td>
<td width="257"><select size="1" name="thissubcat" style="font-size: 9pt; color: #000080">
<option selected value="error">Select One</option>
<?
SelectSubCat($thisprimecat);
?>
</select></td>
</tr>
<tr>
<td width="123" align="right" class="primelink">Value £ :</td>
<td width="257"><input type="text" name="ad_price" size="30" value="<?=trim($_POST['ad_price']);?>" style="font-size: 9pt; color: #000080"></td>
</tr>
<tr>
<td width="123" align="right" class="primelink" valign="top">About
Item:</td>


<td width="257"><textarea rows="10" name="ad_info" cols="36" style="font-size: 8pt; color: #000080"><?=$_POST['ad_info'];?></textarea>
<input type="hidden" name="thisprimecat" value="<?=$_POST['thisprimecat'];?>"></td>
</tr>
</table>
</center>
</div>
<? if ( $_POST['B2'] ) {$BACK ="2";} else {$BACK ="1";} ?>
<p align="center"><input type="submit" value="Submit" name="B2"> <input type="reset" value="Reset" name="B3"> <input type="button" value="Start Over" onClick="history.go(-<? echo $BACK ?>)"></p><u><center><font color="000099">You Will Be Able To Add A Picture On The Next Page</u></center></font>
</form>
&nbsp;</td>
</tr>
<tr>
<td width="458" height="19"><? include("common/adpanel1.php"); ?></td>
</tr>
<tr>
<td width="458" height="19"></td>
</tr>
</table>
</center>
</div>

<!-- main body ends here -->
</td>
</tr>
</table>
</div>
<!-- main body ends and footer begins -->
<?
include("footer.php");
function showpage($ad_ticket,$ad_name,$ad_email) {
include("admin.php");
// send confirmation email
$subject = "Please Confirm Your Classified Ad";
$body = "$ad_name,\n\nPlease Confirm Your Classified Ad for Ad ID: '$ad_ticket' by clicking in the link below.\n$webpath/confirm.php?ad_ticket=$ad_ticket\n\nPlease keep your Ad Code '$ad_ticket' handy. You will need it to modify your Classified Ad.\n\n Thank You,\n\n$admin_name\n$admin_email";
$headers = "From: $admin_email";
mail($ad_email,$subject,$body,$headers);
?>
<!-- header ends and body begins-->
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="801" background="images/backgrd.jpg">
<tr>
<td width="184" valign="top">
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100">
<tr>
<td><font size="1">&nbsp;</font></td>
</tr>
</table>
</center>
</div>
<div align="right">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="159">
<?
GetPrimeCat($thislink);
?>
<tr>
<td width="159" class="primelink">&nbsp;</td>
</tr>
<tr>
<td width="159" class="primelink" align="center">
<?
include("common/adpanel3.php");
?>
</td>
</tr>
<tr>
<td width="159" class="primelink">&nbsp;</td>
</tr>
</table>
</div>
<p>&nbsp;</p>
</td>
<td width="617" valign="top">
<!-- main body begins here -->
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="387">
<tr>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td class="primelink" width="387">&nbsp;</td>
</tr>
<tr>
<td width="387" class="primelink">
<p align="center">Your Classified Ad has been received. Your Ad Code is <b><? echo $ad_ticket ?></b>. Be sure to keep this number handy. You will not be able to modify your Classified Ad in the future.</td>
</tr>
<tr>
<td width="387">&nbsp;</td>
</tr>
<tr>
<td width="387" class="sublink">
<p align="center">Would you like to upload an image?&nbsp; <a class="sublinkalpha" href="uploadimage.php?ad_ticket=<? echo $ad_ticket ?>">Yes?</a> <a class="sublinkalpha" href="index.php">No?</a></td>
</tr>
</table>
</center>
</div>
<!-- main body ends here -->
</td>
</tr>
</table>
</div>
<!-- main body ends and footer begins -->
<?
include("footer.php");
}
?>
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.

Rather than dumping your entire script, please post a [url=http://sscce.org]minimal test case[/url].

[quote="mylifestyle, post: 763943"]I'd like to be able to have the members text read the same as they are inserting which includes line breaks and paragraps as they type them......[/QUOTE]
Use a formatting language and library to parse same, such as [URL="http://php.net/BBCode"]BBCode[/URL] or [URL="http://michelf.com/projects/php-markdown/"]Markdown[/URL].

[quote="mylifestyle, post: 763943"][PHP]<?
[/QUOTE]
Short tags may not be enabled; don't rely on them.

PHP:
		if (!mysql_query("INSERT INTO site_ads VALUES (NULL, '".$ad_ticket."', '".$_POST['thisprimecat']."', '".$_POST['thissubcat']."', '".$_POST['ad_name']."', '".$_POST['ad_email']."', '".$_POST['ad_item']."', '".$ad_price."', '".$_POST['ad_info']."', '', 'n', 'n', 'n', NOW())") )
			die("Error inserting data into database: ".mysql_error());

This is vulnerable to SQL injection. Rather than the outdated mysql driver, use PDO and prepared statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO".

It's also barely readable. Variables are interpolated in double quoted strings, so you don't need to concatenate them:
PHP:
<form method="POST">
    <label for="name">Name:</label>
    <input id="name" name="name" value="<?php if (isset($_REQUEST['name'])) {echo $_REQUEST['name'];} ?>"/>
</form>
<?php
  if (isset($_REQUEST['name'])) {
      "Hello, $_POST[name].";
  }
?>

Don't use die when outputting HTML.

Outputting the result of mysql_error to non-admin users discloses too much information.

PHP:
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" width="801" background="http://x10hosting.com/forums/images/backgrd.jpg">
    <tr>
      <td width="184" valign="top">
        <div align="center">
          <center>
            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100">
              <tr>
                <td><font size="1">&nbsp;</font></td>
              </tr>
            </table>
          </center>
Don't use tables for layout; use styling (which, these days, means CSS).

<center> isn't semantic. HTML should denote the document structure, not its formatting. Use CSS for the latter.
 
Last edited:

mylifestyle

New Member
Messages
117
Reaction score
0
Points
0
Hi.

Thank you so much for all of that..it is very much apppreciated and I'll obv take note of what u said abt dumping
alot of code here....

now...

Unfortunately I am not au-fait with all that html/php stuff so is there anyway you can give me a laymans/idiots version so that
my brain cell may be able to comprehend ? or should I just go away and leave u alone???

Ta
ML
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You don't need to leave me alone, but start by reading the links, then run a few web searches of your own. Read through the PHP language reference; you'll find all sorts of useful features (e.g. magic methods, iterators). Play around on non-critical projects. Try your hand at SQL injections, for example. You can do it to your own code or find a site that is designed to let you write and test exploits (some sites have a sandbox so people can write exploits without actually damaging anything; it's a great way to learn). There's quite a bit of information online about topics such as SQL injection and semantic HTML.

As for your original question, take a look at the documentation for the BBCode and Markdown processors I previously linked to, though it wouldn't hurt to search the web for others. I have no particular recommendations on this front, though the two I linked to should be simple to use (at most two function calls, one to initialized the parser and another to parse a string, converting it to HTML). It doesn't matter too much which you pick (though I'm a fan of markdown).
 
Last edited:
Top