<form method="post" enctype="multipart/form-data" action="saveimage.php">
<table>
<tr>
<td width="250">Email: (will not be publicized)</td>
<td>
<input name="email" type="text" id="email" /><br />
</td>
</tr>
<tr>
<td width="250">Image</td>
<td>
<input name="image" type="file" id="file">
</td>
</tr>
<tr>
<td width="250"> </td>
<td>
<input name="add" type="submit" id="add" value="Order">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['add'])) {
$dbhost = 'localhost';
$dbuser = 'iluxcoke_myuser';
$dbpass = 'qwert';
$db_name = 'inmoti6_mysite';
$tbl_name = 'images_tbl';
$ftp_user = 'admin@ilux.co.ke';
$ftp_pass = 'qwert2012';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db_name")or die("cannot select DB");
$ftp_server = "ftp.ilux.co.ke";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
// login with username and password
$login_result = ftp_login($ftp_conn, $ftp_user, $ftp_pass);
// check connection
if ((!$ftp_conn) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user";
}
$Email = $_POST['email'];
$filePath="http://www.iluxcoke/public_html/admin" . $_FILES["file"]["name"];
// $Type = $_POST['type'];
if ($_FILES["file"]["error"] > 0) {
echo "Error: NO CHOSEN FILE <br />";
echo"INSERT TO DATABASE FAILED";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], __DIR__ . "/upload/" . $_FILES["file"]["name"]);
echo"SAVED<br>";
$sql = "INSERT INTO `images_tbl` ( `id`, `email`, `image`, `submission_date`) VALUES ('$id','$Email','$filePath', curdate())";
if(mysql_query($query_image)) {
echo "Stored in: " . "uploads" . $_FILES["file"]["name"];
} else {
echo 'File name not stored in database';
}
}
}
?>
我试图允许用户输入电子邮件和图片并将其上传到我的网站管理员文件夹但我遇到问题并显示此错误:
Connected to ftp.ilux.co.ke, for user admin@ilux.co.keSAVED
File name not stored in database
答案 0 :(得分:0)
我认为您在mysql_query()函数中使用了错误的SQL字符串。 您正在使用$ query_image,并且您的查询是在$ sql变量中定义的。
请改为尝试:
//HERE IS THE CHANGE
if(mysql_query($sql))
//------------------
{
echo "Stored in: " . "uploads" . $_FILES["file"]["name"];
}
else
{
echo 'File name not stored in database';
}