Forum Activity for @micrexc

alt=
@micrexc
08/25/14 07:04:41AM
1 posts

Can't update record


Using Jamroom

I'm trying to sync three scripts together to get cross domain profile editing working. The scripts are WordPress, BuddyPress, & JamRoom.

The code I'm using go to the test domain, get the profile's information from a php call that returns JSON, and then the JSON can be pushed to the WordPress/BuddyPress database.

The only problem is that I'm a front end developer wearing a backend's hat, so I'm learning as I go.
How can I check to see if the user_id already has entries under field_id (value 1 & 2) that have filled in values? And if that exists, simply update the entries. If it doesn't exist, simply create them.


Code I'm working with:
$band_id = $_GET['band_id'];

$ch = curl_init(); 

// set url 
curl_setopt($ch, CURLOPT_URL, "http://test.yourocktheworld.com/getProfile.php?band_id=".$band_id); 

//return the transfer as a string 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

// $output contains the output string 
$output = curl_exec($ch);

$json_a=json_decode($output,true);

// array method
foreach($json_a[profile] as $p)
{
echo '

Band ID: '.$p[band_id].'

	Band Name: '.$p[band_name].'

	Band Latitude: '.$p[bandlatit].'

	Band Longitude: '.$p[bandlongt].'

';

}

global $current_user;
      get_currentuserinfo();
	echo '<br /><br />WordPress ID: ' . $current_user->ID . "<br /><br />";

// field_id 2 = Longitude
// field_id 3 = Latitude

$wpdb->query("INSERT INTO wp_bp_xprofile_data SET value=$p[bandlongt], field_id=2, user_id=$current_user->ID ON DUPLICATE KEY SET value=$p[bandlongt], field_id=2, user_id=$current_user->ID;");

$wpdb->query("INSERT INTO wp_bp_xprofile_data SET value=$p[bandlatit], field_id=3, user_id=$current_user->ID ON DUPLICATE KEY SET value=$p[bandlatit], field_id=3, user_id=$current_user->ID;");
curl_close($ch);

Columns I'm working with

id,field_id,user_id,"value","last_updated"


updated by @micrexc: 10/06/14 06:13:50PM