<?php
$Name=$_POST['txtName'];
$Desc=$_POST['txtDesc'];
$path1 = $_FILES["txtFile"]["name"];
move_uploaded_file($_FILES["txtFile"]["tmp_name"],"../Products/" .$_FILES["txtFile"]["name"]);
//** Establish Connection with MYSQL
$con = mysql_connect("localhost","root");
// Select Database
mysql_select_db("jmmc", $con);
// Specify the query to Update Record
$sql = "Update admin_category set CategoryName='".$Name."',Description='".$Desc."',Image='".$path1."' where CategoryId=".$Id."";
// Execute query
mysql_query($sql,$con);
// Close The Connection
mysql_close($con);
?>
答案 0 :(得分:0)
向我发送您从代码中获取的错误。 检查您的文件位置路径是否为真
或
可能是你没有创建文件夹产品并检查你的数据库确认你有正确的列名
检查所有变量,例如$ Id,$ Name,$ Desc是否有正确的值 像
(其中CategoryId =&#34;。$ Id。&#34;&#34;)
你需要在表单中定义enctype,方法类型(get或post)并制作如下的html:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="txtFile" >
<input type="hidden" name="txtDesc" value="aaaaa">
<input type="hidden" name="txtName" value="naveed">
<input type="submit" name="submit_button">
</form>
您需要在isset语句中定义PHP代码,如下所示:
<?php
if (isset($_POST['submit_button'])) {
$fileName = $_FILES["txtFile"] ["name"];
if (isset($fileName)) {
$Name=$_POST['txtName'];
$Desc=$_POST['txtDesc'];
$path1 = $_FILES["txtFile"]["name"];
move_uploaded_file($_FILES["txtFile"]["tmp_name"],"../Products/" .$_FILES["txtFile"]["name"]);
//** Establish Connection with MYSQL
$con = mysql_connect("localhost","root");
// Select Database
mysql_select_db("stackoverflow", $con);
// Specify the query to Update Record
$sql = "Update admin_category set CategoryName='".$Name."',Description='".$Desc."',Image='".$path1."' where CategoryId=".$Id."";
// Execute query
mysql_query($sql,$con);
// Close The Connection
mysql_close($con);
}
}
?>