0

I have code like this:

global $wpdb;
    $wpdb->insert(
        'name_of_table',
        array(

            'someInteger' => $surveyResult6,
            'someString' => $surveyResult7
        ),
        array(

            '%d',
            '%s'
        )
    );
    // Increment database rows
    $wpdb->insert_id;
    echo $surveyResult7;

...and I have problem with insert string inside my table.

There' s no error, evrything seems to be fine but there's no new record in my database. If I change string to digit and submit form once again, there appear new row with two digits.

I' ve read some topics with problem like this one (wpdb and strings) but I don't find any clue how to fix it. Could anyone tell me what should I do?

1
  • remove single quote before '%d' , hope this is copy paste error Commented Sep 27, 2017 at 9:08

2 Answers 2

1

You have error in your script

global $wpdb;
    $wpdb->insert(
        'name_of_table',
        array(

            'someInteger' => $surveyResult6,
            'someString' => $surveyResult7
        ),
        array(

            '%d', //<---remove unwanted single quotes
            '%s'
        )
    );
    // Increment database rows
    $wpdb->insert_id;
    echo $surveyResult7;
Sign up to request clarification or add additional context in comments.

3 Comments

I take these from Wordpress'es example: codex.wordpress.org/Class_Reference/wpdb If I remove single quotes I get error: "Parse error: syntax error, unexpected '%', expecting ')'"
check updated answer you also have one extra single quote before '%d',
I removed one, not necesarry single quote before '%d', and do what you wrote but sadly it' s still doesn't work.
0

I resolved my own problem. I write an answer for people with problem like mine.

I don't know why but if you have (for example) 5 variables in form and one of them is string you have to complete form (all fields). If you skip one of input there' s a problem. The strangest is fact, that if you have only digits as a variables to send to your database, you can skip some fields and code will create row with your and empty values.

Comments

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.