Form Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
frosty16
Forum Newbie
Posts: 19
Joined: Sat Jan 26, 2008 6:58 am

Form Query

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Form Query

Post by requinix »

Eliminate the loop and set $value to be whatever it's supposed to be.
frosty16
Forum Newbie
Posts: 19
Joined: Sat Jan 26, 2008 6:58 am

Re: Form Query

Post 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.
Post Reply