在这里我要对MySQL进行插入。但是在这里我得到了错误。我看到有相同的重复但是在那些答案中他们要求添加ISSET。在我的编码中我也添加了但是我还是得到了这个错误。
错误1:注意:未定义的索引:第8行的....... add.php中的描述 错误2:注意:未定义的变量:第9行的.......... \ add.php中的_FILE
错误3:致命错误:在第12行的.... add.php中调用未定义的函数NOW()
我在这里添加了我的编码
<html>
<body>
<?php
include('config.php');
if(isset($_POST['submit']))
{
$Title=$_POST['Title'];
$Description=$_POST['Description'];
$Image = addslashes(file_get_contents($_FILE['Image']));
$Categories = $_POST['category'];
$ModifiedBy = 1;
$ModifiedDate = NOW();
$query1=mysql_query("insert into testdb values('','$Title','$Description','$Image','$Categories','$ModifiedBy',$ModifiedDate,1)");
if($query1)
{
header("location:list.php");
}
}
?>
<fieldset style="width:300px;">
<form method="post" action="" enctype="multipart/form-data">
Title: <input type="text" name="Title"><br>
Description: <input type="text" name="description"><br>
Image : <input type="file" name="Image" /><br>
<select name="category" id="category">
<option>Choose</option>
<option value="1">new</option>
<option value="2">info</option>
<option value="2">Event</option>
<br>
<input type="submit" name="submit">
</form>
</fieldset>
</body>
</html>
答案 0 :(得分:1)
您的代码中存在语法问题。它应该是这样的:
$Title=$_POST['Title'];
$Description=$_POST['description'];
$Image = addslashes(file_get_contents($_FILES['Image']));
$Categories = $_POST['category'];
$ModifiedBy = 1;
$ModifiedDate = 'NOW()';
$query1=mysql_query("insert into testdb values('','$Title','$Description','$Image','$Categories','$ModifiedBy',$ModifiedDate,1)");
答案 1 :(得分:0)
Error 1: Case of "description" is wrong!
Error 2: it should be $_FILES (add an S). Also that is not how you handle file uploads -
[read more here][1]
Error 3: NOW() is a mysql tag. not php. you can use date() if you want this in php.
答案 2 :(得分:0)