Page 1 of 1

Form Query

Posted: Sun Oct 11, 2009 3:09 am
by frosty16
Good Morning

I have got the following code:

Code: Select all

if ( isset( $_POST ) )
        $postArray = &$_POST;           // 4.1.0 or later, use $_POST
    else
        $postArray = &$HTTP_POST_VARS;  // prior to 4.1.0, use HTTP_POST_VARS
        
        foreach ( $postArray as $sForm => $value )
        {
            if ( get_magic_quotes_gpc() )
                $postedValue = htmlspecialchars( stripslashes( $value ) ) ;
            else
                $postedValue = htmlspecialchars( $value ) ;
            
            $user='user';
            $host='localhost';
            $password='password';
            $database='database';
            $con=mysqli_connect($host, $user, $password, $database)
                or die ("Error 201: The SQL Server could not be contacted at this time. please try agian or if the problem persists contact Luke Frost");
            
            $query = "UPDATE oc_message SET Content = '" . $postedValue . "', OC_Name = '" . $_POST['OC_Name'] . "' WHERE URN = 1";
        
            $result=mysqli_query($con, $query)
                or die ("Error 202: The 332 Sqn SQL Server could not be contacted at this time. please try agian or if the problem persists contact Luke Frost");
                
            echo "Home Page has been updated successfully to the following information:<br><br>";
            echo "<strong>OC's Message</strong><br>";
            echo $postedValue;
            echo "<br><br><strong>OC's Name</strong><br>";
            echo $_POST['OC_Name'];
            echo "<br><Br>Page will redirect automatically after 5 seconds.<br>";
            echo "If the page does not refresh click <a href='../WebsiteAdmin_Webpages.php'>here</a>";
        }
The section of updating the database is working fine however on the form there are 3 controls (Textarea class, Textbox, Submit button). When i click submit i want just the content of the textarea class to be saved to the database where are currently the contents of all three controls are being saved one after the other so in the end "submit" ends up on there field because it loops through all the items saving one after another.

What am I doing wrong and how can i stop this happening and just saving the textarea class contents?

Thank you in advance

Frosty

Re: Form Query

Posted: Sun Oct 11, 2009 3:19 am
by requinix
Eliminate the loop and set $value to be whatever it's supposed to be.

Re: Form Query

Posted: Sun Oct 11, 2009 3:22 am
by frosty16
What set the $value to the name of the textarea class? I have tried displaying that however it is the content of the textarea and so will always change depending on the user.

That code is part of a free WYSIWYG editor i have downloaded and am using. That is why i am having to use a text class rather than just a textarea.