Lost content after submit form

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

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

if(isset($_POST["submit"]))
{
   $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?

Thanks

Jeroen
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 10, 2012 4:37 pm
Contact:

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

if(isset($_POST["submit"]))
{
   $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

sparklingdiamond
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Sep 15, 2012 2:44 pm
Contact:

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


?php
session_start();

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


Another method would be putting your information in a database such as MySQL.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 5 guests