将图像加文本插入mysql数据库 [英] Insert image plus text into mysql database

查看:102
本文介绍了将图像加文本插入mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Helo编码器



我正在尝试将文本和文本一起插入mysql数据库,但它无法正常工作。我想将图像类型限制为jpg。这是我的代码。



Helo Coders

I'm trying to insert text along with text to mysql database but it is not working. I would like to restrict the image type to jpg only. Here is my code.

<?php
$username= "root";
$password= "";
$hostname= "localhost";
$dbhandle=mysql_connect($hostname, $username, $password) or die("could not connect to the database");

$selected=mysql_select_db("unic", $dbhandle);
$imageName=mysql_real_escape_string($_FILES["image"]["name"]);
$imageData=mysql_real_escape_string($_FILES["image"]["tmp_name"]);
$imageType=mysql_real_escape_string($_FILES["image"]["type"]);
$extension=strtolower(substr($imageName, strpos($imageName, '.')+ 1));
if(isset($_POST['FullName']) && isset($_POST['YourGender']) && isset($_POST['AgeGroup'])  && isset($_POST['Institution'])  && isset($_POST['Purpose']) && isset($_POST['NRC'])  && isset($_POST['Province']) && isset($_POST['dbDate']) && isset($_POST['NRC'])  && isset($_POST['Province']) && isset($_POST['Address'])){
if(isset($imageName)){
if(!empty($imageName)){
if(($extension=='jpg'||$extension=='jpeg')&&$imageType=='image/jpeg'){
$name=$_POST['FullName'];
$gender=$_POST['YourGender'];
$age=$_POST['AgeGroup'];
$institution=$_POST['Institution'];
$purpose=$_POST['Purpose'];
$nrc=$_POST['NRC'];
$province=$_POST['Province'];
$dbdate=$_POST['dbDate'];
$address=$_POST['Address'];
$query = mysql_query("SELECT * FROM students WHERE NRC='$nrc'");
if(mysql_num_rows($query) > 0){
echo ' The NRC you entered is already taken ';
}else{
mysql_query("INSERT INTO `students` set FullName='$name', Gender='$gender', AgeGroup='$age', Organisation='$institution', Purpose='$purpose', NRC='$nrc', Province='$province', dbDate='$dbdate', Address='$address' Image='$imageName'");
echo("Record was Succesfully Entered");
}
}else{
echo 'Only jpg Images allowed';
}
}
}
}
mysql_close();
?>

推荐答案

username = root;
username= "root";


password = ;
password= "";


hostname = localhost;
hostname= "localhost";


这篇关于将图像加文本插入mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆