Issue with tweet content and storing into mysql table


#1

I am getting user RTs and mentions and storing into table.
It works fine for me and few more test with my friends. But when my one of friend test it from US, Pitsburge it gets stuck in between. How come this happen?

I tested whether issue is with special characters in tweet. I put 〟 、 。 , . ・ : ; ? ! … ‥ ゛ ゜ ´ ` ¨ ^ ° ′ ″ ヽ ヾ ゝ ゞ 〃 all special character in my test, but it works fine. It get data, store into table and redirect to next page. But when my friend from US test it, data stored into table(dont know all tweets or not) and stuck on same page. does not redirect to next page.

I used mysqli_real_escape_string, but when I use it, it does not store tweet in table. When I ignore, it store

What can be other issue?
Threre are two function here.

        function lookup($tweetid,$connection,$userid)
        {
                $tweets5 = $connection->get("https://api.twitter.com/1.1/statuses/retweets/".$tweetid.".json?count=1");
                //var_dump($tweets5);
                $json = json_encode($tweets5);
		$count = 0;
                foreach($tweets5 as $item)
                {
			$count = $count + 1;
                        $text = $item->text;
			$text_id = $item->id;
//                        $user_id = $item->user->id;
                        $name = $item->user->name;
			$constant = 'retweet';
			$time = $item->created_at;
			$dt = \DateTime::createFromFormat('D M d H:i:s e Y', $time);
//			$dt = new \DateTime($time);
			$tweet_time = $dt->format('H:m:s');
			$tweet_dtm = $dt->format('Y:m:d');
			$year =  $dt->format('Y'); 
			$month =  $dt->format('m'); 

			echo $constant."-".$count."<br>".$text."-".$text_id."-".$name."-".$time."-".$tweet_time.$tweet_dtm.$year.$month.$rt_count.$follower.$friend."<br>";


			echo "<br>";
			$inreplyto =  $item->in_reply_to_screen_name;

                     $follower = $item->user->followers_count;
			$rt_count = $item->retweet_count;
                     $friend = $item->user->friends_count;
	              $con = mysqli_connect('127.0.0.1', 'root', 'karim', 'karim');

			$text = mysqli_real_escape_string($text);

	                if (mysqli_connect_errno())
	                {
	                        echo "Failed to connect to MySQL: " . mysqli_connect_error();
	                        return;
	                }

	                $insertQuery1 = "INSERT INTO twitter_retweet(`username`,`userid`,`tweet_text`,`text_id`,`time`,`month`,`year`,`date`,`user_follower_count`,`rt_count`,`constant`,`in_reply_to`) VALUES ('".$name."','".$userid."','".$text."','".$text_id."','".$tweet_time."','".$month."','".$year."','".$tweet_dtm."','".$follower."','".$rt_count."','".$constant."','".$inreplyto."')";

	                if (!mysqli_query($con,$insertQuery1))
	                {
	                //      die('Error: ' . mysqli_error($con));
	                //      echo "error";
	                }

//                        echo  "Text : $text <br>  ID : $user_id <br> Name : $name <br> Follower : $follower <br> Friends : $friend <br> ---";
                }
	

        }
	

	echo '<form name="myForm" id="myForm"  action="start.php" method="POST">
	<input style="display:none" name="userid" value="'.$userid.'" />

	</form>

	<script>
		function submitform()
		{
			document.getElementById("myForm").submit();
		}
		window.onload = submitform;
	</script>
	';