Jump to content

Posting using database information instead of a form


Mavent

Recommended Posts

Normally I'd post example code, but I haven't even gotten that far on this.  Sorry.  I have to send information to a third party in the form of a Post.  What I need to know is: can I grab information from a database, then Post it?  I know Post automatically sends the content of a form, but can I Post without a form, just using information already stored in a database?

 

Thanks in advance!

Pseudo:

 

$sql = "SELECT `first_name`, `last_name` FROM `users_table` WHERE `user_id` = 5 LIMIT 1"; // obviously change query for your needs
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result) == 1) {
	$row = mysql_fetch_assoc($result);

	// being your cURL block
	$ch = curl_init();

	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, array('first_name' => $row['first_name'], 'last_name' => $row['last_name'])); 
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);

	curl_exec($ch);

	curl_close($ch);
}
else {
	echo 'No record found.';
}
}
else {
trigger_error(mysql_error());
}

 

There are more curl_setopt() you might want to look into; I just used the basic to get you going.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.