做PHP总是出现Parse error: syntax error, unexpected T_STRING in C:\wamp\www\yan\login.php on line3
<?phpif(isset($_POST['Submit1'])){$name=$_POST['name'];$pwd1=$_POST['pwd1'];$pwd2=$_P...
<?php
if(isset($_POST['Submit1']))
{$name=$_POST['name'];
$pwd1=$_POST['pwd1'];
$pwd2=$_POST['pwd2'];
$sex=@$_POST['sex'];
$age=$_POST['age'];
$email=$_POST['email'];
$checkid=preg_match('/^\w{1,20}$/',$name); //使用正则表达式检查用户名
$checkpwd1=preg_match('/^\w{6,20}$/',$pwd1);
$checkemail=preg_match('/^[a-zA-Z0-9_\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$email);
if(!$checkid)
echo "<script>alert('用户名设置错误!');</script>";
elseif(!$checkpwd1)
echo "<script>alert('密码设置错误!');</script>";
elseif(!$sex)
echo "<script>alert('性别为必选项!');</script>";
elseif($age&&(!is_numeric($age)))
echo "<script>alert('年龄必须为一个数字!');</script>";
elseif($email&&(!$checkemail))
echo "<script>alert('email格式错误!');</script>";
elseif($pwd1!=$pwd2)
echo "<script>alert('两次输入的密码不一致!');</script>";
else
{
$conn=mysql_connect('localhost','root','123456') or die('连接失败');
mysql_select_db('store_db',$conn) or die("选择数据库失败");
mysql_query("SET NAMES gb2312");
$sql="select * from store_user where name='$name'";
$result=mysql_query($sql);
if(mysql_num_rows($result)!=0)
echo "<script>alert('用户名已存在!');</script>";
else
{
if($email)
{
if($age)
$in_sql="insert into store_user values('$name','$pwd1','$sex','$email','$age')";
else
$in_sql="insert into store_user values('$name','$pwd1','$sex','$email',NULL)";
}
else
{
if($age)
$in_sql="insert into store_user values('$name','$pwd1','$sex',NULL,'$age')";
else
$in_sql="insert into store_user values('$name','$pwd1','$sex',NULL,NULL)";
}
$in_result=mysql_query($in_sql);
if(mysql_affected_rows($conn)==0)
echo "<script>alert('注册失败!');</script>";
else
{
//注册成功后跳转到登录页面
echo "<script>alert('注册成功!');location.href='login.php';</script>";
}
}
}
}
?> 展开
if(isset($_POST['Submit1']))
{$name=$_POST['name'];
$pwd1=$_POST['pwd1'];
$pwd2=$_POST['pwd2'];
$sex=@$_POST['sex'];
$age=$_POST['age'];
$email=$_POST['email'];
$checkid=preg_match('/^\w{1,20}$/',$name); //使用正则表达式检查用户名
$checkpwd1=preg_match('/^\w{6,20}$/',$pwd1);
$checkemail=preg_match('/^[a-zA-Z0-9_\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$email);
if(!$checkid)
echo "<script>alert('用户名设置错误!');</script>";
elseif(!$checkpwd1)
echo "<script>alert('密码设置错误!');</script>";
elseif(!$sex)
echo "<script>alert('性别为必选项!');</script>";
elseif($age&&(!is_numeric($age)))
echo "<script>alert('年龄必须为一个数字!');</script>";
elseif($email&&(!$checkemail))
echo "<script>alert('email格式错误!');</script>";
elseif($pwd1!=$pwd2)
echo "<script>alert('两次输入的密码不一致!');</script>";
else
{
$conn=mysql_connect('localhost','root','123456') or die('连接失败');
mysql_select_db('store_db',$conn) or die("选择数据库失败");
mysql_query("SET NAMES gb2312");
$sql="select * from store_user where name='$name'";
$result=mysql_query($sql);
if(mysql_num_rows($result)!=0)
echo "<script>alert('用户名已存在!');</script>";
else
{
if($email)
{
if($age)
$in_sql="insert into store_user values('$name','$pwd1','$sex','$email','$age')";
else
$in_sql="insert into store_user values('$name','$pwd1','$sex','$email',NULL)";
}
else
{
if($age)
$in_sql="insert into store_user values('$name','$pwd1','$sex',NULL,'$age')";
else
$in_sql="insert into store_user values('$name','$pwd1','$sex',NULL,NULL)";
}
$in_result=mysql_query($in_sql);
if(mysql_affected_rows($conn)==0)
echo "<script>alert('注册失败!');</script>";
else
{
//注册成功后跳转到登录页面
echo "<script>alert('注册成功!');location.href='login.php';</script>";
}
}
}
}
?> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询