|
 |
|
เรื่องการนำข้อมูลที่จะ Insert ไปตรวจสอบกับอีก Table นึง |
|
 |
|
|
 |
 |
|
พอดีอยากจะทำฟอร์ม Login แล้วนำ ช่อง Username ไปตรวจสอบกับอีก Table นึงว่าอนุญาติให้สมัครหรือป่าว จะต้องแทรกโค๊ดยังไงดีครับ
พอดีมือใหม่ เริ่มหัดเขียน จะลองศึกษา Right - left join ก็ไม่รู้จะเอาไปแทรกตรงไหนดี
รบกวนช่วยแนะนำด้วยครับ
code ที่ตรวจสอบ form login ครับ
Code (PHP)
<?
mysql_connect("127.0.0.1","","");
mysql_select_db("register");
mysql_query("SET NAMES UTF8");
if(trim($_POST["login_n"]) == "")
{
header("location:regis_nempty.php");
exit();
}
if(trim($_POST["passw"]) == "")
{
header("location:regis_nempty.php");
exit();
}
if(trim($_POST["rname"]) == "")
{
header("location:regis_nempty.php");
exit();
}
if(trim($_POST["address"]) == "")
{
header("location:regis_nempty.php");
exit();
}
if(trim($_POST["email"]) == "")
{
header("location:regis_nempty.php");
exit();
}
if(trim($_POST["telenumber"]) == "")
{
header("location:regis_nempty.php");
exit();
}
$strSQL = "SELECT * FROM userinfo WHERE login_n ='".trim($_POST['login_n'])."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
header("location:regis_agian.php");
}
else
{
$strSQL = "INSERT INTO userinfo (login_n,passw,rname,address,area,gender,email,telenumber) VALUES ('".$_POST["login_n"]."','".$_POST["passw"]."','".$_POST["rname"]."','".$_POST["address"]."','".$_POST["area"]."','".$_POST["gender"]."','".$_POST["email"]."','".$_POST["telenumber"]."')";
$objQuery = mysql_query($strSQL);
header("location:regis_complett.php");
}
mysql_close();
?>
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2011-05-27 14:17:55
|
 |
 |
 |
 |
Date :
2011-05-27 14:14:35 |
By :
bjungza |
View :
788 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จะตรวจสอบคำต้องห้าม หรือไม่เหมาะสมรึเปล่าครับ (ผมเดาเอาน่ะ  )
Code (PHP)
if(trim($_POST["login_n"]) != "")
{
$loginname=$_POST["login_n"];
$Sql=mysql_query("select * form Table where field LIKE '%".$loginname."%'");//เลือกตัวไหนตัวนึงตามความเหมาะสมครับ
/*หรือ*/
$Sql=mysql_query("select * form Table where field='$loginname'");//เลือกตัวไหนตัวนึงตามความเหมาะสมครับ
$rows = mysql_num_rows($Sql)
if($rows < 1)
{
$strSQL = "INSERT INTO userinfo (login_n,passw,rname,address,area,gender,email,telenumber) VALUES ('".$_POST["login_n"]."','".$_POST["passw"]."','".$_POST["rname"]."','".$_POST["address"]."','".$_POST["area"]."','".$_POST["gender"]."','".$_POST["email"]."','".$_POST["telenumber"]."')";
$objQuery = mysql_query($strSQL);
}
else
{
echo "Username นี้ใช้ไม่ได้ครับ"
}
}
|
ประวัติการแก้ไข 2011-05-27 16:59:24
 |
 |
 |
 |
Date :
2011-05-27 16:58:30 |
By :
mangkunzo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากนะครับ เดี๋ยวจะลองดูน่ะครับ
พอดีไม่ใช่คำต้องห้ามอ่ะครับ แต่ว่าคล้าย ๆ กับว่าถ้าไม่มีชื่อ username ที่กำหนดไว้ใน Table นั้นก็จะไม่สามารถสมัครได้น่ะครับ
เลยงง ๆ ว่าต้องให้มันตรวจสอบ Table จากสองที่ยังไง
|
 |
 |
 |
 |
Date :
2011-05-28 23:04:48 |
By :
bjungza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|