query('set names gb2312'); if(empty($conn)) {"/> query('set names gb2312'); if(empty($conn)) {">

Home  >  Article  >  Backend Development  >  关于PHP和MYSQL的一个有关问题,需求解

关于PHP和MYSQL的一个有关问题,需求解

WBOY
WBOYOriginal
2016-06-13 13:00:41782browse

关于PHP和MYSQL的一个问题,急需求解啊
就是用PHP连接mysql数据库后再查询数据
$conn=mysqli_connect("localhost","root","469201743","my_DB"); 
$conn->query('set names gb2312');
if(empty($conn))
{ die("数据库连接失败");
}
$sql= "SELECT username,phone,qq,email FROM user WHERE username = $name";
$result=$conn->query($sql);
if($row = $result->fetch_row())
这样能从数据库中正确显示所需内容
------解决方案--------------------
为什么 $name 要加引号?
因为 username 是字符类型
为什么 $msgID 不需要加引号?
因为 msgID 是数值类型

我怎么知道的?
你没加,出错了

$pic=$_POST['picfile'];
应为
$pic=$_FILES['picfile'];

手册中说的很清楚了

手册不是教科书,不会教你怎么做(简单的示例还是有的)
手册是工具书,那么都东西神仙才能记得住。记不住时就得翻一翻

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn