所以在下面的index.php页面中,我想将image_info
和username
的值存储到Jquery变量中,这样我就可以使用ajax将它们发送到另一个PHP页面,然后使用$ _POST将这些值存储在表中。这甚至可能吗?如果没有,为什么这(只是为了知识)?如果是这样,我将如何执行此操作?
这是我的index.php页面:
<?php
//dispay the images that the users upload
$conn = mysqli_connect("localhost","root","") or die ("No SQLI");
mysqli_select_db($conn, "sample") or die ("No DB");
$sqli = "SELECT * FROM `photos` ORDER BY `id` DESC";
$result = mysqli_query($conn, $sqli) or die ("No query");
while($row = mysqli_fetch_assoc($result))
{
$username = $row['username'];
$title = $row['title'];
$description = $row['description'];
$image_name = $row['image_name'];
$image_id = $row['image_id'];
$random_directory = $row['random_direc'];
$date = date('Y-m-d');
$image_info = "http://localhost/splindr_2.0/photos/$random_directory/$image_name";
//echo all content in content wrapper
echo "<div id='contentWrapper'>
<div class='photo'>
<div class='actual_image'>
<img src='$image_info'>
</div>
<div class='like_system'><button onClick='increaseT(this)' type='button' class='like_button' name='like_button' id='like_button'>Like</button>
<input disabled type='text' name='total_likes' class='total_likes' value='4'>
<button type='button' class='twitter_button' name='twitter_button'>
<a style='color: #2e4987;text-decoration:none' href='http://www.twitter.com/share?url=$image_info&hashtags=Splindr, CheckThisOut'>Tweet This</a></button>
<button type='button' class='show_comments' name='show_comments'>Comments</button>
<input disabled type='text' class='comment_count' name='comment_count' value='0'>
<button type='button' class='delete_button' name='delete_button' id='delete_button'>
<a style='text-decoration:none;color: #2e4987' href='delete_post.php'>Delete</a>
</button>
</div>
<div class='info_wrapper'>
<div class='info_header'>Title: $title   By: $username   Date: $date</div>
<div class='description'>$description</div>
</div>
<div class='comment_wrapper'>
<div class='close_comment'>[close comments]</div>
<div class='comment_box_wrapper'>
<div class='comment_box'>
<div class='profile_pic'><img src='https://i.imgur.com/1MkFvhU.png'></div>
<div class='actual_comment'>Comment goes here...</div>
</div>
</div>
<div class='post_comment'>
    Post Comment:<input type='text' name='user_comment' id='user_comment'>
<button type='button' class='comment_button' name='sumbit_comment' id='submit_comment'>Comment</button>
</div>
</div>
</div>
</div>
</div>";//end contentWrapper
}
?>