Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在多部分表单上使用AJAX、Javascript和PHP?_Javascript_Php_Jquery_Mysql_Ajax - Fatal编程技术网

如何在多部分表单上使用AJAX、Javascript和PHP?

如何在多部分表单上使用AJAX、Javascript和PHP?,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我有我当前项目的更新状态表。到现在为止,我只能用HTML条目更新我的状态。我想知道我将如何允许用户使用照片进行更新。我知道输入类型必须是“file”,我需要将“enctype=”multipart/form data“添加到表单中。我需要修改wall.js和functions.php的哪些部分以允许使用照片更新状态。我确实有一个upload.php脚本,但不知道如何才能将所有内容一起工作。任何关于下一步尝试的线索或方向都很好 HTML表单 <form method="post" actio

我有我当前项目的更新状态表。到现在为止,我只能用HTML条目更新我的状态。我想知道我将如何允许用户使用照片进行更新。我知道输入类型必须是“file”,我需要将“enctype=”multipart/form data“添加到表单中。我需要修改wall.js和functions.php的哪些部分以允许使用照片更新状态。我确实有一个upload.php脚本,但不知道如何才能将所有内容一起工作。任何关于下一步尝试的线索或方向都很好

HTML表单

<form method="post" action="">
<input type="text" name="update" id="update">
<br />
<input type="submit" id="update_button"  class="update_button"/>
</form>
Functions.php//插入更新

public function Insert_Update($id, $update)
{
$update=htmlentities($update);
$time=time();
$ip=$_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT msg_id,message FROM `messages` WHERE id_fk='$id' order by msg_id desc limit 1") or die(mysql_error());
$result = mysql_fetch_array($query);
if ($update!=$result['message']) {
$query = mysql_query("INSERT INTO `messages` (message, id_fk, ip,created) VALUES ('$update', '$id', '$ip','$time')") or die(mysql_error());
$newquery = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username FROM messages M, users U where M.id_fk=U.id and M.id_fk='$id' order by M.msg_id desc limit 1 ");
$result = mysql_fetch_array($newquery);
return $result;
}
else
{
return false;
}
}
在PHP方面,请参阅PHP手册中的“处理文件上载”部分。您可能希望使用“POST方法上载”(a la the
$\u FILES
magic variable)。阅读其中的所有五个子部分,了解其工作原理并避免出现问题

哦,在将任何用户输入放入SQL查询之前,请确保使用
mysql\u real\u escape\u string()
/
mysql\u escape\u string()
对其进行转义。希望您的示例中没有这些内容,因为您试图保持发布的简短

public function Insert_Update($id, $update)
{
$update=htmlentities($update);
$time=time();
$ip=$_SERVER['REMOTE_ADDR'];
$query = mysql_query("SELECT msg_id,message FROM `messages` WHERE id_fk='$id' order by msg_id desc limit 1") or die(mysql_error());
$result = mysql_fetch_array($query);
if ($update!=$result['message']) {
$query = mysql_query("INSERT INTO `messages` (message, id_fk, ip,created) VALUES ('$update', '$id', '$ip','$time')") or die(mysql_error());
$newquery = mysql_query("SELECT M.msg_id, M.id_fk, M.message, M.created, U.username FROM messages M, users U where M.id_fk=U.id and M.id_fk='$id' order by M.msg_id desc limit 1 ");
$result = mysql_fetch_array($newquery);
return $result;
}
else
{
return false;
}
}