Hi,

I have created a form and since it is very long some of my users need a SAVE feature so that they can enter some details-> save it, and then fill the blank fields in the future.

Most of my form fields are 'textarea' as the data entred by users is going to be very long and may go upto 3-4 para.

Can I do this with PHP and MYSQL and if yes how do I go about it?

Is this the best way to store large text data?

Thanks

Hows this work for you:
<?php

$unique_user_id = $confirmed_logged_in_user_id;
if(isset($_POST['submit'])){
    $i = 0;
    $setsql = '';
    foreach($_POST as $k=>$v){
        $dbfields = array('field1','field2','field3');
        if(in_array($k,$dbfields)){
            $data[$k] = str_replace('"', "&quot;", $v);
            $data[$k] = str_replace("'", "&#39;", $data[$k]);
            if($i == 0){
                $setsql .= "`{$k}` = '{$data[$k]}'";
                $i = 1;
            }else{
                $setsql .= ",`{$k}` = '{$data[$k]}'";
            }
        }else{

        }
    }
    $sql = "UPDATE `table` SET {$setsql} WHERE `uniqueid` = $unique_user_id";
    $result = mysql_query($sql);
}else{
    $sql = "SELECT * from `table` WHERE `uniqueid` = $unique_user_id";
    $result = mysql_query($sql);
    if($result !== false){
        $data = mysql_fetch_assoc($result);
    }
}
?>
<form method='post'>
<textarea name='field1' cols='30' rows='5'><?php echo $data['field1'];?></textarea>
<textarea name='field2' cols='30' rows='5'><?php echo $data['field2'];?></textarea>
<textarea name='field3' cols='30' rows='5'><?php echo $data['field3'];?></textarea>
<input type='submit' name='submit' value='Save Info so far'/>
</form>

It requires each user to have a unique id, they can come back at any time and pull the data they already had using the unique id.

$dbfields = array('field1','field2','field3'); just needs updating to the names of the fields you want editable in your mysql table - then give the form fields the same name and print out $data[$fieldname] as the default value so it will show already entered data for it

Hi,

If it requires a unique id for each user is there a need for a login page or can it be done without a login page.

Thanks

It can be done without a login page, just with no login it means someone could change their id to anything they want and view & edit data other users have entered.

It would be fine if its some internal page staff members/clients(maybe) will be editing but not for public use.

Or on our site i set up when a user visits the site a random token is created and it saves a cookie on the users computer of the token. As long as they leave the token intact they can use it to access data they have entered on the site but once the token is lost they can't get the data back. You could use that sort of setup if you just want the user to have access over a week or so cookies should be fine but for long term i would create logins - they are much more reliable and gives very good security over the data plus lets the user login from a different computer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.