Page 1 of 1

helpin php form

Posted: Sat Jun 20, 2009 2:48 am
by shazi9b
helllo
i have a problem in submited data
when i type the data in textarea as
1
3
5
the output comes as
1 3 5
i want output as i submit
plz help me
my script is given below
index.php

Code: Select all

<form id="form1" name="form1" method="post" action="submit_sms.php">
 
    Name:
    <input name="subform" type="hidden" id="subform" value="1" />
    <br />
    <input name="txtName" type="text" id="txtName" />
    <br />
  Location:<br />
  <input name="txtLocation" type="text" id="txtLocation" />
  <br />
  Mobile:<br />
  <input name="txtMobile" type="text" id="txtMobile" />
  <br />
  Catagory:<br />
  <select name="lstCat" id="lstCat">
    <option value="funny">Funny</option>
    <option value="adult">Adult</option>
    <option value="birthday">Birthday</option>
    <option value="eid_sms">Eid SMS</option>
  </select>
  <br />
  Message:<br />
  <textarea name="txtMessage" id="txtMessage" style="border:1px solid #666666; height:100px;"></textarea>
  <br />
  <input type="submit" name="Submit" value="Submit" />
  </p>
  </form>
<a href="viewsms.php?q=funny">Funny SMS</a> | <a href="viewsms.php?q=Adult">Adult SMS</a> | <a href="viewsms.php?q=birthday">birthday SMS</a> | <a href="viewsms.php?q=eid_sms">Eid SMS</a>


submit_sms.php

Code: Select all

 
 
<?php
 
$name = $_REQUEST["txtName"];
$city = $_REQUEST["txtLocation"];
$mobile = $_REQUEST["txtMobile"];
$cat = $_REQUEST["lstCat"];
$sms = $_REQUEST["txtMessage"];
 
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
 
    mysql_select_db("sms", $con);
 
mysql_query("INSERT INTO tbtest (user_name, user_location, user_mobile, sms_cat, sms_data) 
VALUES ('" . $name ."','" . $city . "','" . $mobile . "','" . $cat . "','" . $sms . "')");
echo "Your Sms Submited Successfully. Thanks ."
 
?>



viewsms.php

Code: Select all

<?php
$q = $_GET['q'];
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("sms", $con);
 
$result = mysql_query("SELECT * FROM tbtest
WHERE sms_cat='" . $q . "'");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['user_name'] . "<br>" . $row['sms_data'];
  echo "<br /><hr>";
  }
 
?>

Re: helpin php form

Posted: Sat Jun 20, 2009 5:25 am
by terier
I don't understand exactly what is your problem... maybe you just need to replace the "\n" character (input from the textarea) to a <br> (html break line)?

Re: helpin php form

Posted: Mon Jun 22, 2009 10:15 am
by shazi9b
actully i want to new line in textarea automatically
\n is not working
and idont know the exact location where i should put the \n or br

Re: helpin php form

Posted: Mon Jun 22, 2009 10:34 am
by papa
nl2br($row['sms_data']);

Re: helpin php form

Posted: Wed Jun 24, 2009 10:06 am
by shazi9b
thanks man its working now
but still there is a problem when i m trying to show in a table its gives error

Re: helpin php form

Posted: Wed Jun 24, 2009 10:33 am
by papa
What error ?