Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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
PHP将文本和图像插入数据库并检索它_Php_Html - Fatal编程技术网

PHP将文本和图像插入数据库并检索它

PHP将文本和图像插入数据库并检索它,php,html,Php,Html,AddStdRecord.php 这是AddStd记录表单,我需要它来访问addoutput.php并在数据库中插入它 添加学生信息 选择要上载的文件: 学生证 姓 名字 中名 生日 性别 男性 女性 地址 父亲的名字 母亲的名字 接触 前辈 取消 添加学生 AddOutput.php 输入到数据库的代码,这有什么问题吗? include_once('connection.php'); $StdID = $_REQUEST['txtID']; $Lname = $_REQUEST['

AddStdRecord.php 这是AddStd记录表单,我需要它来访问addoutput.php并在数据库中插入它 添加学生信息


选择要上载的文件:



学生证 姓 名字 中名 生日 性别

男性 女性

地址 父亲的名字 母亲的名字 接触 前辈 取消 添加学生

AddOutput.php 输入到数据库的代码,这有什么问题吗?
include_once('connection.php');


$StdID = $_REQUEST['txtID'];
$Lname = $_REQUEST['txtLname'];
$Fname = $_REQUEST['txtFname'];
$Mname = $_REQUEST['txtMname'];
$Bday = $_REQUEST['txtBday'];
$Gender = $_REQUEST['rbgender'];
$Add = $_REQUEST['txtAdd'];
$Father = $_REQUEST['txtfather'];
$Mother = $_REQUEST['txtmother'];
$Contact = $_REQUEST['txtcontact'];
$PrevSch = $_REQUEST['txtPrev'];



$target_dir = "StdImg/";
$target_file = $target_dir . basename($_FILES["UploadImage"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
 } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
 }
// Check if file already exists
 if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["UploadImage"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}
}


$sql = "INSERT INTO tblstdpro VALUES ('".$_SERVER['DOCUMENT_ROOT']."\\StdImg\\".$fileToUpload."', '$StdID', '$Lname', '$Fname', '$Mname', '$Bday', '$Gender', '$Add', '$Father', '$Mother', '$Contact', '$PrevSch')";

   if ($conn->query($sql) === TRUE) {
header("Location: AddStdRec.php?");
  } else {
   echo "Error: " . $sql . "<br>" . $conn->error;
 }

$conn->close();
?>
include_once('connection.php');
$StdID=$_请求['txtID'];
$Lname=$\请求['txtLname'];
$Fname=$_请求['txtFname'];
$Mname=$\请求['txtMname'];
$Bday=$_请求['txtBday'];
$SEXT=$_请求['RBSEXT'];
$Add=$_请求['txtAdd'];
$DAVER=$\请求['TXTDEAVER'];
$Mother=$_请求['txtmother'];
$Contact=$_请求['txtcontact'];
$PrevSch=$_请求['txtprov'];
$target_dir=“StdImg/”;
$target\u file=$target\u dir。basename($_文件[“UploadImage”][“name”]);
$uploadOk=1;
$imageFileType=pathinfo($target\u文件,pathinfo\u扩展名);
//检查图像文件是真实图像还是假图像
如果(isset($_POST[“提交”])){
$check=getimagesize($_文件[“fileToUpload”][“tmp_名称]);
如果($check!==false){
echo“文件是图像-”$check[“mime”]。”;
$uploadOk=1;
}否则{
echo“文件不是图像。”;
$uploadOk=0;
}
}
//检查文件是否已经存在
如果(文件_存在($target_文件)){
echo“抱歉,文件已存在。”;
$uploadOk=0;
}
//检查文件大小
如果($_文件[“UploadImage”][“size”]>500000){
echo“对不起,您的文件太大了。”;
$uploadOk=0;
}
//允许某些文件格式
如果($imageFileType!=“jpg”&&&$imageFileType!=“png”&&&$imageFileType!=“jpeg”
&&$imageFileType!=“gif”){
echo“对不起,只允许使用JPG、JPEG、PNG和GIF文件。”;
$uploadOk=0;
}
//检查$uploadOk是否被错误设置为0
如果($uploadOk==0){
echo“抱歉,您的文件未上载。”;
//如果一切正常,请尝试上载文件
}否则{
如果(移动上传的文件($文件[“fileToUpload”][“tmp文件名”],$target文件)){
回显“文件”。已上载basename($\u文件[“fileToUpload”][“name”]);
}否则{
echo“抱歉,上载文件时出错。”;
}
}
$sql=“插入tblstdpro值(“$\u服务器['DOCUMENT_ROOT']”、\\StdImg\“$fileToUpload.”、“$StdID'、'$Lname'、'$Fname'、'$Mname'、'$Bday'、'$Gender'、'$Add'、'$Father'、'$Mother'、'$Contact'、'$PrevSch');
if($conn->query($sql)==TRUE){
标题(“位置:AddStdRec.php?”);
}否则{
echo“Error:”.$sql.“
”$conn->Error; } $conn->close(); ?>

我输入的有错误吗?它会进入主文件夹,但不会进入数据库,我已经搜索了几天关于此功能的内容,但似乎找不到,请评论我的错误,提前谢谢

插入尝试后是否出现错误?不,它不会进入数据库,但会进入路径文件我知道它不会“进入数据库”,但是你有错误吗?根据您的代码,如果插入失败(可能),那么您应该会看到一个错误输出,或者确实发生了头重定向吗?另外,我看不到
$fileToUpload
是如何设置的(续)。。。(你可能已经知道了,但以防万一)。。。但是,由于您不使用insert指定列(这是可以的),因此要插入的值必须与表的列顺序匹配。单击时没有错误,但它不会进入数据库。您可以帮助我修复此代码吗?插入尝试后是否出现错误?否,它不会进入数据库,但会进入路径文件我知道它不会“进入数据库”,但您是否收到错误?根据您的代码,如果插入失败(可能),那么您应该会看到一个错误输出,或者确实发生了头重定向吗?另外,我看不到
$fileToUpload
是如何设置的(续)。。。(你可能已经知道了,但以防万一)。。。但是,由于您不使用insert指定列(这是可以的),因此插入的值必须与表的列顺序匹配。单击时没有错误,但它不会进入数据库。您能帮助我修复此代码吗?
include_once('connection.php');


$StdID = $_REQUEST['txtID'];
$Lname = $_REQUEST['txtLname'];
$Fname = $_REQUEST['txtFname'];
$Mname = $_REQUEST['txtMname'];
$Bday = $_REQUEST['txtBday'];
$Gender = $_REQUEST['rbgender'];
$Add = $_REQUEST['txtAdd'];
$Father = $_REQUEST['txtfather'];
$Mother = $_REQUEST['txtmother'];
$Contact = $_REQUEST['txtcontact'];
$PrevSch = $_REQUEST['txtPrev'];



$target_dir = "StdImg/";
$target_file = $target_dir . basename($_FILES["UploadImage"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
 } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
 }
// Check if file already exists
 if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["UploadImage"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}
}


$sql = "INSERT INTO tblstdpro VALUES ('".$_SERVER['DOCUMENT_ROOT']."\\StdImg\\".$fileToUpload."', '$StdID', '$Lname', '$Fname', '$Mname', '$Bday', '$Gender', '$Add', '$Father', '$Mother', '$Contact', '$PrevSch')";

   if ($conn->query($sql) === TRUE) {
header("Location: AddStdRec.php?");
  } else {
   echo "Error: " . $sql . "<br>" . $conn->error;
 }

$conn->close();
?>