0

I am helping a friend update their website and move it over to a new server. Their old server is running php 5.3.6-13 and the new site is running php 5.5.

There is a custom plugin that uses $wpdb that allows the user to edit some information that is written to a custom table in the database, specifically:

$query = "UPDATE wp_building_plan SET sale_price = '$sale_price', available = '$available', broker_name = '$broker_name', broker_email = '$broker_email',    broker_phone = '$broker_phone' WHERE id = '$unit_id' "; 
$wpdb->query($query);

Here is the actual code for the plugin: http://snippi.com/s/dk7bxvx

On the server running 5.3 the data can be written to the appropriate rows within the wp_building_plan table when info is updated or changed. On the new server running 5.5 when data is changed within the plugin nothing is changed or written to the database at all.

I am trying to find a better way to write the UPDATE wp_building_plan code that is compatible with PHP 5.5

I've checked out the following links and tried to implement them but have not had any success: http://www.php.net/manual/en/function.mysql-db-query.php http://codex.wordpress.org/Class_Reference/wpdb http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/ http://markoheijnen.com/the-future-of-wpdb/

Any tips or pushes in the right direction would be greatly appreciated, d

1
  • Please always put external resources/code into your question. You can still do that with an edit. Just reduce it to the important bits. Then enable debugging in your install. There could be some error messages that hints you.
    – kaiser
    Commented Jan 25, 2014 at 2:06

1 Answer 1

1

There is no difference in this respect between PHP 5.3 and 5.5. The code doesn't need to change.

However, you should still use prepare properly. Like so:

$query = $wpdb->prepare( 'UPDATE wp_building_plan SET sale_price = %s, available = %s, broker_name = %s, broker_email = %s,    broker_phone = %s WHERE id = %s', $sale_price, $available, $broker_name, $broker_email, $broker_phone, $unit_id );
$wpdb->query($query);

If you are seeing a difference between the servers, then the issue is probably with the database itself. Is the table on one of them read-only or some such thing? Does the table even exist? Check the new database using a tool like phpMyAdmin and see what's up there.

2
  • 1
    Otto, Thanks for the reminder about about ->prepare I just tried that and it does not seem to solve the issue although that does look like the proper way to write this...So, the php version thing...I have the site running on my local machine using mamp pro. I can write data to the custom table just fine when I have the php version set to 5.2.17, but when I change it to 5.3.20 or 5.4.1 it stops working. I also have the site running on my server which is running 5.5 and it doesn't there either.
    – derekshirk
    Commented Jan 25, 2014 at 0:43
  • 2
    The PHP version really doesn't matter at all. Your configuration for those versions might, so maybe you have the mysql extension configured differently between the different versions. But nothing about the $wpdb code is version dependent.
    – Otto
    Commented Jan 25, 2014 at 0:45

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.