I am working on a module, "who viewed your profile" in a social networking site project. When a logged in user clicks on hyperlink of a user, he must be directed to a dummy page called view.Information of user who has clicked link of other user and username of user whose link has been clicked is stored in a database table, views. I tried doing this by calling a function updatetable on click of the hyperlink and using this function, I want to send variables viewername and viewedname to view.php, which inserts a record into views table.
我正在开发一个模块,“谁在社交网站项目中查看了您的个人资料”。当登录用户点击用户的超链接时,必须将他定向到一个名为view的虚拟页面。已点击其他用户链接的用户和已点击其链接的用户的用户名信息存储在数据库表中,视图。我尝试通过单击超链接调用函数updatetable并使用此函数,我想将变量viewername和viewingname发送到view.php,它将记录插入到视图表中。
while($row=mysqli_fetch_array($res))
{
?>
<a href="http://localhost/profileviews/view.php" onclick="updatetable('<?php echo $row['username']; ?>','<?php echo $username; ?>')"><?php echo $row['username']; ?></a>
<?php
}
The above code displays links of all users and if a link is clicked, view.php page is opened where some php code has to be run. My updatetable function is as follows:
上面的代码显示了所有用户的链接,如果点击了链接,则会打开view.php页面,其中必须运行一些php代码。我的updatetable函数如下:
<script type="text/javascript">
var viewedname,viewername;
function updatetable(viewedname,viewername)
{
$.post('view.php' { viewer_name:viewername, viewed_name:viewedname } );
alert(viewedname);
}
</script>
if ($_POST && isset($_POST['viewer_name']) && isset($_POST['viewed_name'])) {
$viewer_name = ($_POST['viewer_name']);
$viewed_name = mysql_real_escape_string($_POST['viewed_name']);
$con=new mysqli('localhost','root','','test');
if($con->connect_error) echo $con->connect_error;
$r=mysqli_query($con,"insert into views(viewer,viewed) values('$viewer_name','$viewed_name')");
}
Problems that I am facing: alert is not being shown and insertion is not happening after view.php code. Is there a mistake in the way I'm sending the viewer_name and viewed_name variables? I am new to php. Please help me out! Thank you :)
我面临的问题:没有显示警报,并且在view.php代码之后没有发生插入。我发送viewer_name和Viewed_name变量的方式有错吗?我是php的新手。请帮帮我!谢谢 :)
1 个解决方案
#1
0
Missing a (,
) in your javascript post:
在你的javascript帖子中遗漏了(,):
Replace with:
$.post('view.php', { viewer_name:viewername, viewed_name:viewedname });
PHP:
Its better doing it this way:
它更好地这样做:
if ($_POST){
if(isset($_POST['viewer_name']) && isset($_POST['viewed_name'])) {
//Do your stuff
}
}
#1
0
Missing a (,
) in your javascript post:
在你的javascript帖子中遗漏了(,):
Replace with:
$.post('view.php', { viewer_name:viewername, viewed_name:viewedname });
PHP:
Its better doing it this way:
它更好地这样做:
if ($_POST){
if(isset($_POST['viewer_name']) && isset($_POST['viewed_name'])) {
//Do your stuff
}
}