Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i think the code is like this:</p> <pre><code>$http_dir = 'http://site.com/Amats/image_entry/'; $post_link = $http_dir . $img_newname; if (!empty($name) &amp;&amp; !empty($email) &amp;&amp; !empty($office_id) &amp;&amp; !empty($title) &amp;&amp; !empty($story)) { $save_sql = "INSERT INTO `tbl_contest` (filename, name, email, office_id, title, story, time) VALUES ('$img_newname','$name','$email','$office_id','$title','$story','$sql_date')"; $query = mysql_query($save_sql,$con) or die(mysql_error("Could not write information to the database")); if (mysql_num_rows($con) !== 0) { header('Location:' . $uploadSuccess.'#modal-text'); if($user_id) { // We have a user ID, so probably a logged in user. try { $ret_obj = $facebook-&gt;api('/me/feed', 'POST', array( 'link' =&gt; $post_link, 'message' =&gt; 'Posting with the PHP SDK!' )); echo '&lt;pre&gt;Post ID: ' . $ret_obj['id'] . '&lt;/pre&gt;'; //save post_id to MySQL $post_id = $ret_obj['id']; $save_id = "INSERT INTO `tbl_mytable` (post_id) VALUES ('$post_id')"; $query = mysql_query($save_id,$con) or die(mysql_error("Could not write information to the database")); //save post_id to MySQL // Give the user a logout link echo '&lt;br /&gt;&lt;a href="' . $facebook-&gt;getLogoutUrl() . '"&gt;logout&lt;/a&gt;'; } catch(FacebookApiException $e) { $login_url = $facebook-&gt;getLoginUrl( array( 'scope' =&gt; 'publish_stream' )); echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;'; error_log($e-&gt;getType()); error_log($e-&gt;getMessage()); } } else { // No user, so print a link for the user to login $login_url = $facebook-&gt;getLoginUrl( array( 'scope' =&gt; 'publish_stream' ) ); echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;'; } } mysqli_close($con); } </code></pre> <p>and you can create some functions to post FB. i use curl to post FB, not use FB PHP SDK. code</p> <pre><code>$arr['token'] = {your token}; $arr['content'] = {content}; $arr['url'] = {share url}; //save post_id to MySQL $post_id = fb_post($arr); $save_id = "INSERT INTO `mytable` (fb_id) VALUES ('$post_id')"; $query = mysql_query($save_id,$con) or die(mysql_error("Could not write information to the database")); //save post_id to MySQL function fb_post($post){ $arr['url'] = "https://graph.facebook.com/me/feed/"; $arr['content'] = array( 'access_token'=&gt;$post['token'], 'message' =&gt; $post['content'], 'link' =&gt; $post['url'] ); $re = fb_post_c($arr); $temp = json_decode($re); return $temp-&gt;id; } function fb_post_c($arr){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $arr['url']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, 'Expect:'); curl_setopt($ch, CURLOPT_POSTFIELDS ,http_build_query($arr['content'])); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); $re = curl_exec($ch); curl_close($ch); return $re; } </code></pre> <p>with the fb php sdk</p> <pre><code>session_start(); require_once 'facebook.php'; $config = array(); $config['appId'] = {your appid}; $config['secret'] = {your secret}; $facebook = new Facebook($config); $user_id = $facebook-&gt;getUser(); if($user_id){ $_SESSION['token'] = $facebook-&gt;getAccessToken(); $arr['content'] = {content}; $arr['url'] = {share url}; $post_id = fb_post_c($arr); if($post_id){ db_in($post_id); echo 'your post id' . $post_id; } }else{ $params = array( 'scope' =&gt; 'publish_stream,user_activities', 'redirect_uri' =&gt; 'http://XXXXXXXXXXX/' ); $facebook-&gt;setExtendedAccessToken(); $loginUrl = $facebook-&gt;getLoginUrl($params); echo "&lt;a href ='".$loginUrl."'&gt;login&lt;/a&gt;&lt;br /&gt;"; } function db_in($post_id){ global $con;//your database ini $save_id = "INSERT INTO `mytable` (fb_id) VALUES ('$post_id')"; $query = mysql_query($save_id,$con) or die(mysql_error("Could not write information to the database")); } function fb_post_c($arr){ global $facebook; try { $ret_obj = $facebook-&gt;api('/me/feed', 'POST', array( 'link' =&gt; $arr['url'], 'message' =&gt; $arr['content'] )); return $ret_obj['id']; } catch(FacebookApiException $e) { return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload