我試圖用AJAX和PHP更新我的數據庫。我確定一切都是正確的,只有我的頁面刷新了,沒有插入到我的表格中。用AJAX插入記錄不插入和刷新頁面
HTML
<form id="salary-upd">
<input type="text" class="defaultText" id="monthly-income" name="monthly-income" title="What is your salary?">
<input type="submit" class="salary-upd-submit">
</form>
<div></div>
AJAX
// UPDATE INCOME
$(".salary-upd-submit").click(function() {
var elem = $(this);
$.post("update_salary.php", elem.parent("#salary-upd").serialize(), function(data) {
elem.next("div").html(data);
});
});
PHP
$uid = $_SESSION['oauth_id'];
$monthly_income = $_POST['monthly-income'];
#update Record
$query = mysql_query("SET `income` (user_id, monthly_income) VALUES ($uid, '$monthly_income')") or die(mysql_error());
嘗試更新我的PHP,因爲我認爲這可能是...
$query = mysql_query("UPDATE `income` SET (user_id, monthly_income) VALUES ($uid, '$monthly_income')") or die(mysql_error());
此壺乞求SQL注入。消除你的輸入! – Quassnoi 2012-04-25 20:07:28
**不要將原始用戶輸入傳遞給SQL。**使用'mysqli_'或'PDO'而不是'mysql_'函數,這些函數已被棄用。 – DCoder 2012-04-25 20:07:46
@DCoder我會歡迎'mysql_'被棄用,但據我所知,他們不是:-( – jeroen 2012-04-25 20:14:10