Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Lost content after submit form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Lost content after submit form

Postby xuquang » Tue Sep 11, 2012 7:01 am

I have a contact us page with fields:
- Name
- Email
- Content

After client submit, I use _$REQUEST to get it

Code: Select all
   $txtName = $_REQUEST['txtName'];
   $txtEmail = $_REQUEST['txtEmail'];
   $txtContent = $_REQUEST['txtContent'];   
        // Insert data to database

But, sometimes, I lost data (txtContent ) on database. Please help me, I could not understand why?

New php-forum User
New php-forum User
Posts: 2
Joined: Tue Sep 11, 2012 6:28 am

Re: Lost content after submit form

Postby Jeroen » Tue Sep 11, 2012 7:34 am

It is a big guess, as there is no actual code posted that can cause your problem. But this is my guess:

You need to sanitize your data before putting it in your database:

Code: Select all
   $txtName = mysql_real_escape_string($_REQUEST['txtName']);
 //or (not so save)
   $txtEmail = htmlspecialchars($_REQUEST['txtEmail'], ENT_QUOTES);
 // DONT do this
   $txtContent = addslashes($_REQUEST['txtContent']);   
        // Insert data to database

Better is to use prepare statements, you can do that with mysqli or PDO
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 10, 2012 4:37 pm

Re: Lost content after submit form

Postby sparklingdiamond » Sat Sep 15, 2012 3:29 pm

To retain your data for a longer person of time use can make use
of PHP session variables. These retain information regardless of
where you move to another page. Example

Code: Select all


$name=$_POST["name"]; //collect data via post

Another method would be putting your information in a database such as MySQL.
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Sep 15, 2012 2:44 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.