Search code examples
phpandroidmysqlinsertmysql-real-escape-string

MySQL PHP - Missing character after forward slash


I have a php script that inserts data from an Android app into a MySQL DB. Some of the submitted values are set to "N/A" text when submitted. I have confirmed that the values sent from the Android device are indeed "N/A". All of the "N/A" text values are saved correctly to my MySQL DB except for at two fields/columns. The values appear as "N/" in these two fields/columns instead of "N/A". I am using mysql_real_escape_string() on the entered data.

The data is sent as a JSON object string to the PHP script:

$q = json_decode(stripslashes($_POST['questionnaire']), true);

This is a section of the php script where the values are inserted into MySQL DB. It is the values at q3_7 and q4_3 that are truncated from "N/A" to "N/":

$query_insert = "INSERT INTO people (q_id, first_name, surname, gender, age, race, q2_7, q2_8, q2_9, q2_10, q2_11, q2_11_1, q3_1, q3_2, q3_3, q3_4, q3_5, 
                q3_6, q3_7, q3_8, q3_9, q3_10, q3_11_1, q3_11_2, q3_11_3, q3_12, q3_13, q4_1, q4_2, q4_3, q4_4, q4_5, q5_1, q5_2, q5_3) VALUES";
$values = "";
$count = 0;
foreach ($q[people] as $entry) {
    $values .= "('".mysql_real_escape_string($q[qID])."', '".mysql_real_escape_string($entry[firstName])."', '".mysql_real_escape_string($entry[surname])."',
                '".mysql_real_escape_string($entry[gender])."', '".mysql_real_escape_string($entry[age])."', '".mysql_real_escape_string($entry[race])."',
                '".mysql_real_escape_string($entry[q2_7])."', '".mysql_real_escape_string($entry[q2_8])."', '".mysql_real_escape_string($entry[q2_9])."',
                '".mysql_real_escape_string($entry[q2_10])."', '".mysql_real_escape_string($entry[q2_11])."', '".mysql_real_escape_string($entry[q2_11_1])."', 
                '".mysql_real_escape_string($entry[q3_1])."', '".mysql_real_escape_string($entry[q3_2])."', '".mysql_real_escape_string($entry[q3_3])."', 
                '".mysql_real_escape_string($entry[q3_4])."', '".mysql_real_escape_string($entry[q3_5])."', $first_map_insert_id + $count*2, 
                '".mysql_real_escape_string($entry[q3_7])."', '".mysql_real_escape_string($entry[q3_8])."', '".mysql_real_escape_string($entry[q3_9])."', 
                '".mysql_real_escape_string($entry[q3_10])."', '".mysql_real_escape_string($entry[q3_11_1])."', '".mysql_real_escape_string($entry[q3_11_2])."', 
                '".mysql_real_escape_string($entry[q3_11_3])."', '".mysql_real_escape_string($entry[q3_12])."', '".mysql_real_escape_string($entry[q3_13])."', 
                '".mysql_real_escape_string($entry[q4_1])."', $first_map_insert_id + $count*2 + 1, '".mysql_real_escape_string($entry[q4_3])."', 
                '".mysql_real_escape_string($entry[q4_4])."', '".mysql_real_escape_string($entry[q4_5])."', '".mysql_real_escape_string($entry[q5_1])."', 
                '".mysql_real_escape_string($entry[q5_2])."', '".mysql_real_escape_string($entry[q5_3])."'),";
    $count++;
}
$query_insert = $query_insert . substr($values, 0, -1) . ";";
$result = mysql_query($query_insert) or errorReport("Error in query: $query_insert. ".mysql_error());

As mentioned the "N/A" text values are only truncated to "N/" at two of the fields. The rest of the values for the other fields are saved correctly as "N/A". Any ideas or help would be appreciated.


Solution

  • Input length must not exceed database table column length.

    Maybe these two fields is shorter, on database table?