Mavent Posted May 22, 2012 Share Posted May 22, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/262938-posting-using-database-information-instead-of-a-form/ Share on other sites More sharing options...
mrMarcus Posted May 22, 2012 Share Posted May 22, 2012 Yes, use curl. Quote Link to comment https://forums.phpfreaks.com/topic/262938-posting-using-database-information-instead-of-a-form/#findComment-1347686 Share on other sites More sharing options...
scootstah Posted May 22, 2012 Share Posted May 22, 2012 You can also use http_post_data if you have the HTTP PECL package installed. Quote Link to comment https://forums.phpfreaks.com/topic/262938-posting-using-database-information-instead-of-a-form/#findComment-1347691 Share on other sites More sharing options...
Mavent Posted May 22, 2012 Author Share Posted May 22, 2012 Yes, use curl. Ah, that was my second guess. My first guess was to try something like: $_POST['text'] = 'another value'; but it didn't seem to work the way I thought it would. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/262938-posting-using-database-information-instead-of-a-form/#findComment-1347694 Share on other sites More sharing options...
mrMarcus Posted May 22, 2012 Share Posted May 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262938-posting-using-database-information-instead-of-a-form/#findComment-1347699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.