同时上传数据并将数据形成数据库

时间:2013-09-12 19:07:48

标签: php

我正在创建html表单,它从表单中获取输入并存储在数据库中并从用户处获取图像并存储在同一个表中

我已在表格中创建了BLOB日期类型的图像字段

但问题是任务不能同时工作

//我的HTML代码

Scholarship name (association name) :<input type ="text" name ="name"/>
Scholarship type (merit/need) :<input type ="text" name ="type"/>
Amount offer by Scholar ship :<input type ="text" name ="rupees"/>
Last date of submission :<input type ="text" name ="last_date"/>
Number of student that can apply :<input type ="text" name ="total_students"/>
 Tagline about scholarship :<input type ="text" name ="tagline"/>
Scholarship criteria(zakaat/profit) :<input type ="text" name ="criteria"/> 
Contact number:<input type ="text" name ="cellno1"/>
Email Address:<input type ="text" name ="email"/>
Scholarship description : <TEXTAREA Name="description" ROWS=2 COLS=20></TEXTAREA>
<input type="file" name="file" /> </br>
<input type="submit" value="Upload and submit">

//我的php代码

<?php
$mysql = new mysqli('localhost','root','******','scholarships_system') or die ('you\'re dead');
if(!empty($_POST['submit'])) && (isset($_FILES['file'])== true)) {

$name= $_POST['name'];
$type = $_POST['type'];
$rupees = $_POST['rupees'];
$last_date = $_POST['last_date'];
$total_students = $_POST['total_students'];
$description = $_POST['description'];
$file = $_FILES['file'];
$data = addslashes(file_get_contents($file['tmp_name']));
$myquery="INSERT INTO scholarship_details  VALUES('','$name','$type','$rupees','$last_date','$total_students','$description'$data)";
if($update=$mysql->query($myquery)or die($mysql->error)){
echo 'congraxx';
}
}
?>

///请帮助我tommorow是我的代码提交,没有错误出现

1 个答案:

答案 0 :(得分:0)

回复您的$myquery变量,您会发现在'$description'$data之间缺少逗号。此外,您缺少包含'的单引号$data

$myquery="INSERT INTO scholarship_details  VALUES('','$name','$type','$rupees','$last_date','$total_students','$description'$data)";

应该是

$myquery="INSERT INTO scholarship_details  VALUES('','$name','$type','$rupees','$last_date','$total_students','$description','$data')";

尽管如此,我没有看到将图像存储在数据库中的重点,除非您有自己的理由这样做。如果不是这种情况,请将其保存在文件目录中并将/path/to/the/image_file.ext存储在数据库中。