PHP向MSSQL插入数据时判断 某个字段是否有重复。 求助大神!!
<?php
require 'account.php';
//------UID的分配-------
$uida = rand(10,999);
$uidb = rand(2,99);
function seed()
{
list($msec, $sec) = explode(' ', microtime());
return (float) $sec;
}
srand(seed());
$uidc =rand(1,99);
$accountid = $uida.$uidb.$uidc;
//------输出accountid-------
//mysql_query("set names utf8");
if(strlen($_GET['account']) > 0) {
$zhanghao = $_GET['account'];
$mima = md5($_GET['password']);
$mimas = md5($_GET['passwords']);
$email = $_GET['emai'];
$tgren = $_GET['tgren'];
if ($mima != $mimas){
exit("<script type='text/javascript'>alert('两次输入的密码不一致');location.href='register.php?id=$tgren'</script>");
}
$ip = getip();
$con = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("连接出错");//IP
mysql_select_db($dbname,$con);
mysql_query("set names 'latin1'");
$time = date("Ymd");
$sql="INSERT INTO $dbzh (account_id,name,phone,email,address,password,pointtime,netbar_ip) values ('$accountid','$zhanghao','$tgren','$email','$zsyb','$mima','$time','$ip')";
if(mysql_query($sql,$con)==false){
//$title ="Sorry"; //return 'no';
exit("<script type='text/javascript'>alert('注册失败,账号已存在!');location.href='register.php?id=$tgren'</script>");
}else{
exit("<script type='text/javascript'>alert('$zhanghao 恭喜您注册成功!');location.href='login.php'</script>");
//$title ="ok"; //return 'ok';
}
}
exit("<script type='text/javascript'>alert('错误!');location.href='index.php'</script>");
?>
我发的这个源码是PHP+MYSQL的,很无奈,对MSSQL不熟,试了好多命令都搞不定。。求哪位大大帮忙改成PHP+MSSQL的。。我就是想让用户在提交表单的时候,先到数据库查一下,没有重复的就插入,重复的则注册失败。。在线等,万分感谢!!