จะเขียนโค้ดสมัครสมาชิกไม่ให้ user และ email ซ้ำ
จะเขียนโค้ดสมัครสมาชิกไม่ให้ user และ email ซ้ำ จะต้องเขียนเพิ่มอย่างไรจากโค้ดนี้ครับ
<?php
$host="127.0.0.1";
$user="root";
$passwd="1234";
$dbname="custom-guitar";
mysql_connect($host,$user,$passwd) or die ("ติดต่อ host ไม่ได้");
mysql_select_db($dbname) or die ("!Database is not");
$checkadd="select * from Member where UserName='$UserName'";
$result=mysql_db_query($dbname,$checkadd);
$num=mysql_num_rows($result);
if($num==0)
{
$sql = "INSERT INTO Member (UserName,FirstName,LastName,Password,Telephone,Email,Address)
VALUES ('$UserName','$FirstName','$LastName','$Password','$Telephone','$Email','$Address')";
mysql_query("set Name tis620");
$sqlquery=mysql_db_query($dbname,$sql);
print"<br>Success";
echo '<meta http-equiv="refresh" content="0;url=Main.php">';
}
elseif($num>0)
{
print"<br>A duplicate, please use a different name and email";
echo '<meta http-equiv="refresh" content="2;url=Main.php">';
}
else
{
print"<br>System failure or an error !!!";
echo '<meta http-equiv="refresh" content="2;url=Main.php">';
}
mysql_close();
?>
<?php
$host="127.0.0.1";
$user="root";
$passwd="1234";
$dbname="custom-guitar";
mysql_connect($host,$user,$passwd) or die ("ติดต่อ host ไม่ได้");
mysql_select_db($dbname) or die ("!Database is not");
$checkadd="select * from Member where UserName='$UserName'";
$result=mysql_db_query($dbname,$checkadd);
$num=mysql_num_rows($result);
if($num==0)
{
$sql = "INSERT INTO Member (UserName,FirstName,LastName,Password,Telephone,Email,Address)
VALUES ('$UserName','$FirstName','$LastName','$Password','$Telephone','$Email','$Address')";
mysql_query("set Name tis620");
$sqlquery=mysql_db_query($dbname,$sql);
print"<br>Success";
echo '<meta http-equiv="refresh" content="0;url=Main.php">';
}
elseif($num>0)
{
print"<br>A duplicate, please use a different name and email";
echo '<meta http-equiv="refresh" content="2;url=Main.php">';
}
else
{
print"<br>System failure or an error !!!";
echo '<meta http-equiv="refresh" content="2;url=Main.php">';
}
mysql_close();
?>
SELECT * FROM member WHERE UserName=$Username OR Email=$Email
ขอบคุณมากครับ
ขอบคุณมากฮะ