php - Can't get variables to work in WPDB UPDATE query -


i've tried can query not work. i've tried prepare, adding ' both variables, adding ' set variable, using springf, using formatted string both values inserted %s, nothing works. i've spent whole night on , right feel crying.

this query works when hard-code values or paste dump directly in phpmyadmin.

$trans = strval($_post["trans"]); $status = strval($_post["status"]);  global $wpdb; $wpdb->show_errors; $query = "update donations set donation_status='".mysql_real_escape_string($status)."' donation_reference = '".mysql_real_escape_string($trans)."'";  $result = $wpdb->query($query);  $wpdb->print_error;  exit( var_dump( $wpdb->last_query ) ); 

another funny thing query works when replace first 2 lines hard-coded values, like:

$trans = "12345678"; $status = "transaction successful"; 

but long values read $_post variables, query doesn't work.

i'm using php version 5.3.28 , mysql 5.5.40.

please help!

first of all, make sure $_post contains expect.

then added security, use wpdb::update() method instead of wpdb::query()

$trans = strval($_post["trans"]); $status = strval($_post["status"]);  global $wpdb; $wpdb->show_errors; $wdpb->update(     'donations',     array( 'dontion_status' => $status ),     array( 'donation_reference' => $trans ), ); $wpdb->print_error;  exit( var_dump( $wpdb->last_query ) ); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -