這裏是我的javascript代碼從JavaScript內部調用PHP函數?
<script>
$(document).ready(function(){
$(".five").click(function(){
<?php echo updatepoints();?>
});
});
</script>
這裏是我的PHP代碼
<?php
function updatepoints() {
mysql_connect("localhost","user","password") or die (mysql_error());
mysql_select_db("database") or die ("Cannot connect to database");
$query = mysql_query("SELECT *from member WHERE username='" . $_SESSION["username"] . "'");
$row=mysql_fetch_array($query);
$points = $row["points"];
$points = $points + 5;
mysql_query("UPDATE member set points='" . $points . "' WHERE username='" . $_SESSION["username"] . "'");
}
?>
這兩個代碼是同一個頁面下方其他。這似乎沒有更新值。我應該如何繼續?
如果你想要它在點擊生活加載該PHP需要做AJAX。這個實例只會在頁面加載完成時加載一次php。看看AJAX jQuery – Rasclatt 2014-10-01 04:26:36
* ...加上,*我認爲你有'session_start();'加載某處? – 2014-10-01 04:28:04
嘗試回顯更新查詢並執行它以查找任何錯誤。 – Jenz 2014-10-01 04:30:25