is there a common problem that would cause my textarea to break the update query if it has more text than a single sentence in it?

The update query runs fine when I only input a single sentence, but anything more than a sentence breaks the query.

Here is the form code:

<form id="cp_files_admin_form" method="post" enctype="multipart/form-data"> 

<label>File Manager Login Text</label>
<input id="login_text" type="text" name="login_text" value="File Manager Login">

<hr>    

<label>File Manager Login Logo</label>
<input id="login_logo" type="file" name="login_logo">

<hr>    

<label>Main Left Logo</label>
<input id="main_left_logo" type="file" name="main_left_logo">

<hr>    

<img class="form-img" src="" alt="">

<label>Main Center Logo</label> 
<input id="main_center_logo" type="file" name="main_center_logo">   

<hr>    

<label>File Manager Instructions Text</label>   
<textarea id="instructions_text" name="instructions_text" style="width:630px;height:150px;"></textarea>


<input id="submit" type="submit" value="Submit">

</form>

Here is the jQuery code:

$(document).ready(function() {

    // Update CMS
    $(document).on('click', '#submit', function() { // catch the form's submit event
            // Send data to server through the ajax call
            // action is functionality we want to call and outputJSON is our data

            // fetch the data for the form
            var data = $('#cp_files_admin_form').serialize();

            console.log('Form Data Before Sent: '+data);

            $.ajax({
                url: 'update.php',
                data: data,
                type: 'GET',                   
                async: 'true',
                dataType: 'json',
                success: function (result) {
                    if(result.status) {
                        alert('CMS Update Successful!');      
                        getCMS();                    
                    } else {
                        alert('CMS Update unsuccessful!'); 
                    }
                },
                error: function (request,error) {
                    // This callback function will trigger on unsuccessful action                
                    alert('Network error has occurred please try again!');
                }
            });                   

        return false; // cancel original event to prevent form submitting
    }); 


});

Here is the update.php code:

<?php

    header("Access-Control-Allow-Origin: *");

    require_once("debug/chromephp.php");

    $formData = $_GET;

    ChromePhp::log('$_GET Data: '.$formData['instructions_text']);

    require_once("config.php");

    $login_text = $formData['login_text'];
    //$login_logo = $formData['login_logo'];
    //$main_left_logo = $formData['main_left_logo'];
    //$main_center_logo = $formData['main_center_logo'];
    $instructions_text = $formData['instructions_text'];

    $sql="UPDATE cp_cms SET login_text='$login_text', instructions_text='$instructions_text' WHERE id = 1";

    $result = mysql_query($sql);

    if($result) {

        // Success
        $output = array('status' => true, 'massage' => 'Success!');
        echo json_encode($output);

    } else {

        // Failed
        $output = array('status' => false, 'massage' => 'Failed!');
        echo json_encode($output);

    }

?>

Screenshot of table structure:

table_structure Any help is much appreciated.

有帮助吗?

解决方案

try this, it prevents entries in the form from breaking your sql queries. Which is also called SQL-Injection Attack ...

$sql="UPDATE cp_cms SET login_text='".
mysql_real_escape_string($login_text)."', instructions_text='".
mysql_real_escape_string($instructions_text)."' WHERE id = 1";

but please have a look at PDO it is so much safer and easier ...

Edit: I dug some PDO example up: http://www.phpeveryday.com/articles/PDO-Prepared-Statement-P552.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top