4 replies
Hi

I am trying to create a PHP which collects name & address then save it as txt file but having hard time getting one of the variable to put information in one cell.

The script is

Input1 Name
Input2 Tel No
Input3 Address

Input3 is textarea with may be more than 2 lines.

Output I want is all in one row.

Column 1 Name1
Column 2 Tel1
Column3 Address ( all lines as one cell)

So all of this is one line. Next line for next name and so.

I can get column1 and column2 to work but address columns gets all out of line. This is what I end up

Row1 Column1 Name1
Row1 Column2 Tel no
Row1 Column3 Address line1
Row2 Column3 Address line2
Row3 Column3 Address line3
Row3 Column1 Name2
Row3 Column2 Tel No


Is there a solution for this?

Thanks
Sukh
#php #textarea
  • Profile picture of the author imarketstuff
    hey there

    posting a snippet of your code may help with your question... so ppl can get a visual

    also, it's possible that you need to strip the "newline" and/or "carriage return" characters from the textarea when it is submitted.

    peace
    Signature
    I MARKET STUFF

    {{ DiscussionBoard.errors[1972717].message }}
  • Profile picture of the author Rickmci
    Originally Posted by blackjack View Post

    Hi



    Is there a solution for this?

    Thanks
    Sukh

    Hey can you post your source code. Hard to debg coose you can not see. If you can I will be glad to have a look for ya..
    Signature

    Visit dotProject Project Management Software for free 60 day Project Management Software.

    {{ DiscussionBoard.errors[1972851].message }}
    • Profile picture of the author blackjack
      Hi

      here is the script

      Code:
      
      this is the function in PHP
      
      
      
      if (isset($_POST['update']))
      {
      	$delimiter = "|";
      	$name = $_POST['name'];
      	$tel=$_POST['tel'];
      	$address=$_POST['address'];
      	$filename = "test.txt";
      	$fp = fopen($filename, "w");
      	$con = $name . $delimiter . $tel . $delimiter . $address."\n"; 
      	fwrite($fp, $con);
      	fclose($fp);
      	echo "Update Compeleted";
      	
      }
      
      
      	
      ********************	
      
      thi is Code on the page
      
      <form id="form1" name="form1" method="post" action="">
      
      <table>
      	
      	<tr>
      		
      		<td> <b> Name :    </b></td>
      	</tr>
      	<tr>
      		
      	
       		<td><input type="text" size="100" name="name" id="name" /></td>
      	</tr>
      	
      	<tr>
      		
      		<td><b>Tel :  </b></td>
      	</tr>
      	<tr>
      		
       		<td><input type="text" size="100" name="tel" id="tel" /></td>
      	</tr>
      	
      	<tr>
      		
      		<td><b> Address :  </b> </td>
      	</tr>
      	<tr>
      		
      		<td><textarea rows="10" cols="100" name="address" id="address"></textarea></td>
      	</tr>
      	
      	<tr>
      	
      		<td><input name="update" type="submit" id="update" value="Update" /></td>
      	</tr>
      </table>
      	
      </form>
      All address data needs to be in one cell in one column.

      Thank for your help
      {{ DiscussionBoard.errors[1973015].message }}
  • Profile picture of the author theIMgeek
    REPLACE:

    $address=$_POST['address'];

    WITH:

    $address = str_replace(array("\n","\r"),', ',$_POST['address']);

    As imarketstuff suggested, that will replace all line breaks with a comma.

    Line 1
    Line 2
    Line 3

    will be saved as Line 1, Line 2, Line 3

    -Ryan
    Signature
    FREE WSO: Protect and Automatically Deliver Your Digital Products

    Ask the Internet Marketing Geek
    <-- Happy to help with technical challenges
    MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
    {{ DiscussionBoard.errors[1973132].message }}

Trending Topics