0

i am trying to store the user entered form data (using php )to a .txt file..

and when i am trying to display the .txt file using php .. the contents are displayed along with the delimiter ( ||) ..how do i get rid of the delimiter in the display ..

i.e. the display is like :

john||mk||mlm||klm||lkm||lkm||lmlk||mkl||female||January||9||2004||ljnbjknjlnln||Expert||

the code i used for above is :

<?php
foreach (glob("formda.txt") as $filename) {   
    $file = $filename;
    $contents = file($file); 
    $string = implode($contents); 
    echo nl2br($string);
    
}
?>

plz do let me know ..how to get rid of the delimiter in the display ???

and can i have the above display in a tabular format ???

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
27
Replies
28
Views
7 Years
Discussion Span
Last Post by archik123
0
<html>
    <body>
<?php
$contents = 'john||mk||mlm||klm||lkm||lkm||lmlk||mkl||female||January||9||2004||ljnbjknjlnln||Expert||';
$chunks = explode('||', $contents);

foreach($chunks as $chunk){
    print $chunk . '<br />';
}
?>
    </body>
</html>

Sure you can also put it in tabular format. I don't know how many columns you want.

0

Thanks for the reply ...

12 cols are required along with the headings as Fname ,Mname ,Lname ..

and in the DATE OF BIRTH COLUMN ( i need to combine 3 cols .. i.e. MONTH ,DAY ,YEAR) INTO 1 COLUMN..
and how do i get the table border displayed?

0
<?php
foreach (glob("formda.txt") as $filename) {   
    $file = $filename;
    $contents = file($file); 
	
    $string = implode($contents); 
	$contents = str_replace(" ",'&nbsp;',$contents);
  /*  echo nl2br($string);*/
   $str1=explode("||",$string);
   
   
  foreach ($str1 as $str2) {
     
   
      

     
	 
	  
     echo nl2br(" $str2 &nbsp;&nbsp; ");	
	
     
  }

 
} 
 

?>

I tried in the above way .. and i got rid of the delimiter in the display ..But how do i display it in the tabular format ... please do let me know..

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

I tried it in the way u mentioned .. it was working ..But now how do i get the tabular display of the data along with the headings ..and border ...

0

More difficult than I thought. Try something like this.

<html>
    <body>
        
<?php
//Build an array of column headers
$hdr[] = 'Fname';
$hdr[] = 'Mname';
$hdr[] = 'Lname';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'Sex';
$hdr[] = 'Date of Birth';
$hdr[] = 'etc.';
$hdr[] = 'Experience';

//Create a new array of data with elements corresponding to column headers
$disp = array();
$file_handle = fopen("/home/david/Programming/apache/httpd/formda.txt", "r");
while (!feof($file_handle)) {
    $line = fgets($file_handle);
    $chunks = explode('||', $line);//Remove delimiters and put data into an array
    $bdate = $chunks[9] . ' ' . $chunks[10] . ', ' . $chunks[11];
    array_splice($disp, count($disp), 0, array_slice($chunks,0,8));
    array_push($disp, $bdate);
    $disp = array_merge($disp, array_slice($chunks,12,2));
}
fclose($file_handle);

//print_r($disp);
$startrow = 0;
$endrow = 0;
echo '<table>';
echo '<tr>';
foreach ($hdr as $h){
    echo '<th>';
    echo $h;
    echo '</th>';
}
echo '<tr>';

foreach($disp as $index=>$data){
    $endrow = 1;
    if ($index % 11 == 0){
        $startrow = 1;
        $endrow = 0;
        echo '</tr><tr>';
    }
    echo '<td>';
    echo $data;
    echo '</td>';
    //if ($index % 11 == 0 && $endrow == 1){
    //    $startrow = 0;
    //    echo '</tr>';
    //}
}
echo '</table>';
?>

    </body>
</html>
0

Thanks for the response ...


The display is not proper ..

I have a total of 18 cols ..(Fname ,Mname ,Lname ,ADDR1 ,ADDR2 ,CITY,STATE,ZIP ,HOME PHONE ,CELL PHONE, E-MAIL ADDRESS ,GENDER ,DOB_MONTH ,DOB_DAY ,DOB_YEAR ,MEDICAL CONDITION,EXPERIENCE ,CATEGORY ...

1. Out of these 18 cols ..i need to merge the data of THE COLS (ADDR1,ADDR2,CITY,STATE,ZIP) into one cell ... and also need to merge the data of the cols (DOB_MONTH,DOB_DAY ,DOB_YEAR) cols into one cell ..

2. I have tried the code mentioned above ..but the display is not proper ..i..e Few of the cols data is missing in the display ..i.e.,,


Fname Mname Lname Address City State Zip Homephone Cellphone Sex
lkmk lmkl mkl mk mlm klm lkm lkm mkl female, January 9 2004


3. What changes in the code should be done for proper display of all records ?

please let me know.

0

I have done minor changes and i am able to get a better display than the previous one ..But the only problem is how do i fit the table size suitable for the printing purpose ...

here goes my ouput :

Fname Mname Lname Address City State Zip Homephone Cellphone
lkmk lmkl mkl mk mlm hsd 6766 87543783 84378327587

As i have more than 14 cols in my ouput ..so while printing out ..its is truncating the last cols in the display ..


I do need the perfect display of all the cols..

what should i do ?

0

Instead of using a text (.txt) file, I would suggest you make it an html file, so you easily format it using a table, applying td's in between each column. I guess you can go about that.

0

We are needed to use .txt file only .. So how can i get a display of the format :

Name ,Mname ,Lname

Addr ,City ,State ,zip

e-mail adress

etc..


for each record..

can u suggest a for loop ..

as the number of records are not known in advance ..

0
<?php

/*/Sequentialise the index for $h_data, such that (FOR EXAMPLE), THE VALUE
	at index 0 is 'Fname';
		     1 is 'Mname'; 
		  ...
		  
*/
$h_data = new array(); //Formal definition (fulfil righteousness)
$h_data[] = 'Fname';
$h_data[] = 'Mname';
//...

/*/Sequentialise the index for $r_data, such that (FOR EXAMPLE), 
	index 0 is for Fname;
		  1 is for Mname; 
		  ...
		  
*/
$r_data = new array(); //Formal definition (fulfil righteousness)
$r_data[] = stripslashes($_POST['Fname']);
$r_data[] = stripslashes($_POST['Mname']);
//...

//Begin main
if (!count($r_data)) {
	echo "<p>There are no values</p>";
} else {
	//Let's begin table
	echo "<table cellpadding='1' cellspacing='0' border='0' width='100%'>";
	
	//Begin by printing table thead
	echo "<tr style='background-color: #BBB'>";
	for ($i = 0; $i < count($h_data); $i++) {
		echo "<td style='color: white'>{$h_data[$i]}</td>"; //No specific formatting/sizing for cells. Define as appropriate. Else, browser defined.
	}
	echo "</tr>";
	//Header ends
	
	//Begin the content from database
	for ($i = 0, $j = true; $i < count($r_data); $i++, $j=!$j) {
		$colour = $j ? "#EEE" : "white"; 
		echo "<tr style='background-color: $colour; text-align: left'>"; //Begin row
		echo "<td>{$r_data[$i]}</td>";
		echo "</tr>"; //End row
	}
	
	//Close table
	echo "</table>";
	
}

?>
0

But where do u give the filename.txt ??

<?php

/*/Sequentialise the index for $h_data, such that (FOR EXAMPLE), THE VALUE
	at index 0 is 'Fname';
		     1 is 'Mname'; 
		  ...
		  
*/
$h_data = new array(); //Formal definition (fulfil righteousness)
$h_data[] = 'Fname';
$h_data[] = 'Mname';
//...

/*/Sequentialise the index for $r_data, such that (FOR EXAMPLE), 
	index 0 is for Fname;
		  1 is for Mname; 
		  ...
		  
*/
$r_data = new array(); //Formal definition (fulfil righteousness)
$r_data[] = stripslashes($_POST['Fname']);
$r_data[] = stripslashes($_POST['Mname']);
//...

//Begin main
if (!count($r_data)) {
	echo "<p>There are no values</p>";
} else {
	//Let's begin table
	echo "<table cellpadding='1' cellspacing='0' border='0' width='100%'>";
	
	//Begin by printing table thead
	echo "<tr style='background-color: #BBB'>";
	for ($i = 0; $i < count($h_data); $i++) {
		echo "<td style='color: white'>{$h_data[$i]}</td>"; //No specific formatting/sizing for cells. Define as appropriate. Else, browser defined.
	}
	echo "</tr>";
	//Header ends
	
	//Begin the content from database
	for ($i = 0, $j = true; $i < count($r_data); $i++, $j=!$j) {
		$colour = $j ? "#EEE" : "white"; 
		echo "<tr style='background-color: $colour; text-align: left'>"; //Begin row
		echo "<td>{$r_data[$i]}</td>";
		echo "</tr>"; //End row
	}
	
	//Close table
	echo "</table>";
	
}

?>
0

Hey ..thanks for the response d5e5..


The below code is working ..But the only problem is : that the last column is disappearing when trying to take the printout the displayed data ..But the requirement is that all the columns should be displayed for printing purpose ...


So how do i adjust the table so that all the cols appear exactly in the display
of the printout??//

Is their anyway to modify the code to get solved with this issue ? do let me know..


More difficult than I thought. Try something like this.

<html>
    <body>
        
<?php
//Build an array of column headers
$hdr[] = 'Fname';
$hdr[] = 'Mname';
$hdr[] = 'Lname';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'etc.';
$hdr[] = 'Sex';
$hdr[] = 'Date of Birth';
$hdr[] = 'etc.';
$hdr[] = 'Experience';

//Create a new array of data with elements corresponding to column headers
$disp = array();
$file_handle = fopen("/home/david/Programming/apache/httpd/formda.txt", "r");
while (!feof($file_handle)) {
    $line = fgets($file_handle);
    $chunks = explode('||', $line);//Remove delimiters and put data into an array
    $bdate = $chunks[9] . ' ' . $chunks[10] . ', ' . $chunks[11];
    array_splice($disp, count($disp), 0, array_slice($chunks,0,8));
    array_push($disp, $bdate);
    $disp = array_merge($disp, array_slice($chunks,12,2));
}
fclose($file_handle);

//print_r($disp);
$startrow = 0;
$endrow = 0;
echo '<table>';
echo '<tr>';
foreach ($hdr as $h){
    echo '<th>';
    echo $h;
    echo '</th>';
}
echo '<tr>';

foreach($disp as $index=>$data){
    $endrow = 1;
    if ($index % 11 == 0){
        $startrow = 1;
        $endrow = 0;
        echo '</tr><tr>';
    }
    echo '<td>';
    echo $data;
    echo '</td>';
    //if ($index % 11 == 0 && $endrow == 1){
    //    $startrow = 0;
    //    echo '</tr>';
    //}
}
echo '</table>';
?>

    </body>
</html>
0

One more thing ..what if i want to merge the first 3 cols data into one cell ..

i have used COLSPAN=3 in <th> ..but it is not working ...

what should be modified? to have the merging of first 3 cells into one ...

Hey ..thanks for the response d5e5..


The below code is working ..But the only problem is : that the last column is disappearing when trying to take the printout the displayed data ..But the requirement is that all the columns should be displayed for printing purpose ...


So how do i adjust the table so that all the cols appear exactly in the display
of the printout??//

Is their anyway to modify the code to get solved with this issue ? do let me know..

0

One more thing ..what if i want to merge the first 3 cols data into one cell ..

i have used COLSPAN=3 in <th> ..but it is not working ...

what should be modified? to have the merging of first 3 cells into one ...

Before experimenting further with your php scripts, I think a good approach to designing your page would be to create what you want to see as a static html page first, using one row of sample data having the maximum number of expected characters in each column. That would be easier to work with. Once you have an html page that displays the one sample row nicely, you can use this page as a model for creating your php page, including your script to read the text file and dynamically build the table rows.

So far, many of your questions, such as how to set the table border, merge columns, fit all the headers on the page, etc. pertain to HTML and CSS. You may get better responses to those questions on the HTML and CSS forum.

0

nks for the response ..I have made minor changes and it was working fine ..But the only thing is while the data is being stored in a .txt file ..the data is appearing like this :

i.e.

Marie||dana||denny|| 4765 ,orange groove|| street 21||escondido||ca||90605||74583593859||7543563849||cool.america9@gmail.com||female||July||14||1996||
perfect ||Expert||Senior

Now how do i set so that the data appears on one row ... instead of breaking into two?

My code is ;

<?php

$fp = fopen("formda1.txt" ,"a");

$savestring = $Fname . "||" .$Mname . "||" .$Lname . "||" .$addr . "||" .$addr2. "||" .$cit. "||" .$stat . "||" .$zip. "||" .$home. "||" .$cell. "||" .$em."||".$gender."||".$dob_month."||".$dob_day."||".$dob_year."||".$mcond."||".$Experience. "||" .$category;
fwrite($fp,$savestring);
fclose($fp);

?>

I tried with using \n ( and br ) .Its not working..


Before experimenting further with your php scripts, I think a good approach to designing your page would be to create what you want to see as a static html page first, using one row of sample data having the maximum number of expected characters in each column. That would be easier to work with. Once you have an html page that displays the one sample row nicely, you can use this page as a model for creating your php page, including your script to read the text file and dynamically build the table rows.

So far, many of your questions, such as how to set the table border, merge columns, fit all the headers on the page, etc. pertain to HTML and CSS. You may get better responses to those questions on the HTML and CSS forum.

0

Could you post the contents of your formda1.txt file here, between [code] paste exact contents of file here [/code] tags please? When you say the line appears broken in two, I think maybe your text editor is just wrapping it. Do you have a way to view the End Of Line characters? I don't see how your script is inserting newline characters in your string. If your data line doesn't contain newline characters, and only appears to because your text editor has word-wrap enabled, then there is nothing to fix (except to get a better text editor, so that you can set word-wrap to 'off').

0

Code of formda1.txt is :

<?php

$fp = fopen("formda1.txt" ,"a");

$savestring = $Fname . "||" .$Mname . "||" .$Lname . "||" .$addr . "||" .$addr2. "||" .$cit. "||" .$stat . "||" .$zip. "||" .$home. "||" .$cell. "||" .$em."||".$gender."||".$dob_month."||".$dob_day."||".$dob_year."||".$mcond."||".$Experience. "||" .$category ."\n";
fwrite($fp,$savestring);
fclose($fp);

?>


output displayed is :

1.Lucy||marie||denny|| 34444,main|| street||san diego||ca||9246656||74583593859||57899||cool.america9@gmail.com||male||Febuary||15||1990||fit||Expert||Teen
2.Marie||dana||denny|| 4765 ,orange groove|| street 21||escondido||ca||90605||74583593859||7543563849||cool.america9@gmail.com||female||July||14||1996||
perfect ||Expert||Senior

0

I use Notepad++ ...

Could you post the contents of your formda1.txt file here, between [code] paste exact contents of file here [/code] tags please? When you say the line appears broken in two, I think maybe your text editor is just wrapping it. Do you have a way to view the End Of Line characters? I don't see how your script is inserting newline characters in your string. If your data line doesn't contain newline characters, and only appears to because your text editor has word-wrap enabled, then there is nothing to fix (except to get a better text editor, so that you can set word-wrap to 'off').

0

After assigning the values to $savestring and before writing $savestring to the file, try adding the following two statements:

$savestring = str_replace("\r", '', $savestring);
$savestring = str_replace("\n", '', $savestring);
0

I tried as u said .. it worked .. But now, how can I display data in tabular form together with the titles .. and the border ...

0

I tried as u said .. it worked .. But now, how can I display data in tabular form together with the titles .. and the border ...

archik123 started this thread on the subject of removing delimiter from data. Please start a new thread to ask your question about displaying data in an html table. That is a separate topic and it would be confusing to ask a new question on page 3 of archik123's thread.:)

0

I am trying to verify the authentication of user login ..

login page is :


<form id="form10" method="post" action="confolog.php">

<fieldset><legend> Personal Information </legend>

User Name : <input type="text" size="15" maxlength ="15" name="Fname"/> &nbsp;&nbsp;

Password: <input type="password" size="15" maxlength="15" name="pwd"/> &nbsp; &nbsp;

<br/>


&nbsp; <input type="submit" value="Submit" name="slog"/>

&nbsp; &nbsp;

<input type="reset" value="Reset" name="res"/>

<br/>


and verification page is

$Fname=$_POST;
$pwd=$_POST;
$encrypted_myname= md5($Fname);
$encrypted_mypassword= md5($pwd);

//echo "encrypting " . $encrypted_myname;
//echo "encrypting " . $encrypted_mypassword;

if (isset($_POST)){

if($Fname == $encrypted_myname && $pwd == $encrypted_mypassword) {
echo "welcome back , " . $Fname;
}

else {
include ('reglog.php');
echo "username and password do not match ";
}
}

else{
include ('reglog.php');
echo "enter your username";
}

i am not able to verify the user authentication ..so where am i going wrong..please do let me know..

0

I am trying to verify the authentication of user login ..

login page is :


<form id="form10" method="post" action="confolog.php">

<fieldset><legend> Personal Information </legend>

User Name : <input type="text" size="15" maxlength ="15" name="Fname"/> &nbsp;&nbsp;

Password: <input type="password" size="15" maxlength="15" name="pwd"/> &nbsp; &nbsp;

<br/>


&nbsp; <input type="submit" value="Submit" name="slog"/>

&nbsp; &nbsp;

<input type="reset" value="Reset" name="res"/>

<br/>


and verification page is

$Fname=$_POST;
$pwd=$_POST;
$encrypted_myname= md5($Fname);
$encrypted_mypassword= md5($pwd);

//echo "encrypting " . $encrypted_myname;
//echo "encrypting " . $encrypted_mypassword;

if (isset($_POST)){

if($Fname == $encrypted_myname && $pwd == $encrypted_mypassword) {
echo "welcome back , " . $Fname;
}

else {
include ('reglog.php');
echo "username and password do not match ";
}
}

else{
include ('reglog.php');
echo "enter your username";
}

i am not able to verify the user authentication ..so where am i going wrong..please do let me know..

0

The encrypted username and the encrypted passwords are being stored in a .txt file ;


like :

(filename.txt)


4b83c256a7ee37fef090378006304e15||8a7d7ba288ca0f0ea1ecf975b026e8e1
88e52ee42fd090896f69d0d71e339d94||d6118c0081ba0ecf1a4f9338d0b21cda

0

The encrypted username and the encrypted passwords are being stored in a .txt file ;


like :

(filename.txt)


4b83c256a7ee37fef090378006304e15||8a7d7ba288ca0f0ea1ecf975b026e8e1
88e52ee42fd090896f69d0d71e339d94||d6118c0081ba0ecf1a4f9338d0b21cda

0

what is storing of user entered form data using MYSQL database on opatija . Can anyone help me with this ?

0

I would like to upload my educational projects and access them?i..e we need a remote server to upload the projects and access the projects by typing in the url . How can we have access to a remote server for free .?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.