<?php
error_reporting(0);
$conn=mysql_connect('mysql.sql135.cdncenter.net','sq_liujian123','qq243376129')or die('数据库连接错误');
mysql_select_db('sq_liujian123',$conn);
mysql_query("set names 'utf8'");//检测会员名称是否存在;
$username = $_POST['username'];
// $sql="select * from user where name=" + $username;
$us=$_POST[name];
$ps= $_POST[password];strlen($us);if($username){
//$res=mysql_query($sql)or die("查询失败!");
echo $us."222222";
$sex=$_POST['sex'];
$age=$_POST['age'];
$qq=$_POST['qq'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$address=$_POST['address'];
// if(is_array(mysql_fetch_row($res))){
// echo "该会员名已经存在!";
// }else{
$sql="insert into users(username,password,sex,age,qq,phone,email,address) values('$us','$ps',$sex,$age,$qq,'$phone','$email','$address')";
echo $sql;
mysql_query($sql)or die("注册失败");
echo"<script>alert('注册成功');location.href='login.php'</script>";
// }
}
function utf_substr($str, $len)
{
for ($i = 0; $i < $len; $i++) {
$temp_str = substr($str, 0, 1);
if (ord($temp_str) > 127) {
$i++;
if ($i < $len) {
$new_str[] = substr($str, 0, 3);
$str = substr($str, 3);
}
} else {
$new_str[] = substr($str, 0, 1);
$str = substr($str, 1);
}
}
return join($new_str);
}
?>// $sql="select * from user where name=" + $username;
为什么这句执行的时候,就会查询失败
解决方案 »
- php函数调用问题
- 关于图像函数的一个问题
- 为什么用localhost,127.0.0.1可以访问,但用ip却不行(apache+php+mysql)?
- 这种数组该如何输出
- 该正则如何设置multiline属性,使得可以匹配多行,答完就结贴
- $this有什么特殊函义吗??在没生成$this对像时到处都在用!特别是在封装类的时候!!初学者!
- PHP实现免费短信发送的技术细节,请高手指点一二!
- vbb问题
- 装好win2k+apache+PHP,浏览时变成了下载“/”,求助
- Linux下制作PHP网站,在windows上无法播放avi视频
- bindec(decbin( 这是什么意思? 为什么要这么用?
- 遇到的一个C的问题
代码改成这样试试:
// $sql="select * from user where name=" + " ' "+$username+" ' ";
这样清晰点
$sql = "select * from user where name='$username'";
2.字符变量用单引号或者双引号括起来应为:
$sql="select * from user where name=‘" . $username."'";
需要加上引号
$sql = "select * from user where name='".$username."'";