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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.