user379888
user379888

Reputation:

Storing webforms data within PHP pages

I was reading a book about PHP and I wanted to know how can you store data(of web forms) in PHP pages? I know the process of creating a php file and recieving the data using $_POST(or any other way like this). But those values would be overwritten when you submit the webform again.

Without using the database or emailing the data, is there a way to store multiple webform's data in PHP?

Upvotes: 0

Views: 120

Answers (2)

Marc Went
Marc Went

Reputation: 144

The easiest way is using a database, since MySQL is working very well together with php, often a php server includes MySQL and phpmyadmin which makes it easier to create and edit the database, then you just need a php script you include at the top op your page to set up the MySQL connection.

If this didn't convince you to use a database you could use this code as well:

$filename = "<your filename here>";
$content = "username=".$_POST['username'].":password=".$_POST['password']."{etc etc etc}."\n";

file_put_contents($filename,$content,FILE_APPEND);

The code above adds a row with the content to your file with the delimiter : (colon).

Make sure the filename already exitst somthing like: data.txt

Upvotes: 0

Dor
Dor

Reputation: 902

If you want to store submissions from multiple sessions (or clients), you'd have to use some sort of database. It could be an RDBMS like MySQL, and it could be a simple file: http://www.dummies.com/how-to/content/storing-data-with-php-flat-file-or-database.html

Upvotes: 2

Related Questions