我有这个脚本:
var wall_user_id = "<?php echo $_SESSION['user_id'];?>";
$.ajax({
type: "POST",
url: "insert.php",
data: "user_id=" + wall_user_id,
success: function () {
$('ul#posts').prepend(wall_post);
}
});//end success function
将 wall_user_id 发送到 php 脚本:
<?php
require 'core/functions/init.php';
$user_id = mysql_real_escape_string($_POST['user_id']);
$sql = 'INSERT INTO wall (user_id) VALUES('.$user_id.')';
mysql_query($sql);
?>
这工作正常,但如果我尝试添加更多这样的值,它不会:
var wall_user_id = "<?php echo $_SESSION['user_id'];?>";
var wall_userimage = "<?php echo $user_data['imagename']; ?>";
$.ajax({
type: "POST",
url: "insert.php",
data: "user_id=" + wall_user_id +"userimage="+ wall_userimage,
success: function () {
$('ul#posts').prepend(wall_post);
}
});//end success function
和 insert.php:
<?php
require 'core/functions/init.php';
$user_id = mysql_real_escape_string($_POST['user_id']);
$userimage = mysql_real_escape_string($_POST['userimage']);
$sql = 'INSERT INTO wall (user_id, image) VALUES('.$user_id.','.$userimage.')';
mysql_query($sql);
?>
它不会向数据库中插入任何值。我究竟做错了什么?