1

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.

2
  • Maybe these two fields is shorter, on database table? Commented Jun 19, 2012 at 7:48
  • Noooooo, you are right! Can I be so noob. :( Commented Jun 19, 2012 at 7:51

2 Answers 2

1

Input length must not exceed database table column length.

Maybe these two fields is shorter, on database table?

Sign up to request clarification or add additional context in comments.

Comments

0

The only way I could think of it is the length of that column/fields are short which leads to the truncation.

E.g. your N/A has length 3 so you field must be at least of length three.

3 Comments

As stated in the comments, that was the case
Yes, thanks. That is the correct answer although Aurimas beat you to it. Not sure how to accept a comment as answer?
@Rynardt You'll have to wait for him to post it up or ask him. You can't accept comments as the correct answer - edit lol he just placed it ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.