|
|
|
ผมอยากจะทำโค้ดเกี่ยวกับห้าม insert ข้อมูลซ้ำ เมื่อ user มีข้อมูลอยู่ในบานข้อมูลเเล้ว |
|
|
|
|
|
|
|
นี้เป็นโค้ด insert ข้อมูลครับ
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function back1(){
alert("**ลงทะเบียนสำเร็จเเล้ว**กรุณาอย่ากรอกซ้ำ");
location.href="check_status_student.php";
}
</script>
<?php
include('config.inc.php');
$_users_name=$_POST['users_name'];
$_users_surname=$_POST['users_surname'];
$_users_number=$_POST['users_number'];
$_users_number1=$_POST['users_sex'];
$_users_number1=$_POST['users_number1'];
$_users_faculty=$_POST['users_faculty'];
$_users_Major=$_POST['users_Major'];
$_users_tel=$_POST['users_tel'];
$_users_email=$_POST['users_email'];
$_users_dormitory=$_POST['users_dormitory'];
if($_POST['users_name']=="" || $_POST['users_surname']=="" || $_POST['users_number']==""||$_POST['users_sex']=="" || $_POST['users_number1']=="" || $_POST['users_faculty']=="" || $_POST['users_Major']=="" || $_POST['users_tel']=="" || $_POST['users_email']=="" || $_POST['users_dormitory']==""){
echo "<script language='javascript'>alert('กรุณากรอกข้อมูลให้ครบ');history.back();</script>";
}else {
$strSQL = "SELECT * FROM detail_id_dorm where Detail_ID_name='".$_POST['users_dormitory']."'";
$objQuery = mysql_query($strSQL);
$nums=mysql_num_rows($objQuery);
$objResult = mysql_fetch_array($objQuery);
$limit=$objResult["limit_room"];
$count=$objResult["count"];
//echo "count === $count <br>";
$total=$count+1;
//echo "total === $total <br>";
if($count>=$limit){
echo "<script language='javascript'>alert('เต็มแล้ว !!!!!');history.back();</script>";
}
else {
$SQL = "INSERT INTO register_dorm_online" ;
$SQL .="(Study_name,Study_surname,Study_number,Study_sex,Study_number1, Study_faculty,Study_major,Study_tel,Study_e_mail,Study_dormitory,date) VALUES ('".$_POST["users_name"]."','".$_POST["users_surname"]."' ,'".$_POST["users_number"]."','".$_POST["users_sex"]."', '".$_POST["users_number1"]."','".$_POST["users_faculty"]."',
'".$_POST["users_Major"]."','".$_POST["users_tel"]."', '".$_POST["users_email"]."','".$_POST["users_dormitory"]."','".date("Y-m-d h:i:s")."')";
$obj = mysql_query($SQL);
if($obj){
echo '<script>back1();</script>';
}
else{
echo "<script language='javascript'>alert('error');history.back();</script>";
}
$strSQL = "UPDATE detail_id_dorm SET ";
$strSQL .="count = '".$total."' ";
$strSQL .="WHERE Detail_ID_name='".$_POST['users_dormitory']."' ";
$objQuery=mysql_query($strSQL);
if($objQuery){
echo "<script language='javascript'>alert('save done');history.back();</script>";
}
else{
echo "<script language='javascript'>alert('error');history.back();</script>";
}
}
}
/*
if($objQuery)
{
echo "<script language='javascript'>alert('completed');history.back();</script>";
}
else
{
echo "<script language='javascript'>alert('error');history.back();</script>";
}*/
mysql_close();
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-01-21 10:10:24 |
By :
boysnider |
View :
1098 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"มีข้อมูลอยู่ในบานข้อมูลเเล้ว"
เขียนให้ชัดเจนครับ คืออะไร ??
|
|
|
|
|
Date :
2013-01-21 10:12:07 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
######### Check Name ############
function checkname($table,$name){
$sql = "select * from $table where name = '".$name."'";
$result = mysql_query($sql) or die(mysql_error().$sql);
$row = mysql_num_rows($result);
if($row>0){
return $row;
}
}
เวลาตรวจสอบก็ใช้
if(checkname($table,$name)!=1)
{
}else{
}
|
|
|
|
|
Date :
2013-01-21 11:09:02 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* ฐานข้อมูลครับ
|
|
|
|
|
Date :
2013-01-21 13:50:37 |
By :
boysnider |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|