I managed to find a way with facebook, but no so much with Twitter. The only progress I got is only with text, but I want it with my image that I shared.
Here is the code:
<?php
$db = mysqli_connect("localhost", "root", "", "photos");
$sql = "SELECT * FROM images ORDER BY id DESC";
$result = mysqli_query($db, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<a href='uploads/".$row['image']."' data-caption='".$row['text']."'> ";
echo "<img id='img_div' src='uploads/".$row['image']."'/>";
//echo "<p id='img_div'>".$row['desc']."</p>";
echo "</a>";
echo"<p id='p_div'>Share</p>";
echo "<a href='http://www.facebook.com/sharer/sharer.php?u=www.example.com/uploads/".$row['image']."'>
<i id='share_div' class='fa fa-facebook fa-lg' aria-hidden='true'></i></a>";
echo "<a id='tweet_div' href='http://www.twitter.com/share?text=Check out this image from "Quotin"!&url=http://www.eample.com/uploads/".$row['image']."'&via=_Quotin_'>Tweet</a>";
}
?>