|
|
|
ขอทุกท่านช่วยเเนะนำการเขียน code เกี่ยวกับ การเช็คว่ามีชื่อซ้ำกันหรือไม่ (ชื่อ login) จนปํญญาเเล้วคับท่านผู้รู้ทุกท่านช่วยที่คับ |
|
|
|
|
|
|
|
ขอทุกท่านช่วยเเนะนำการเขียน code เกี่ยวกับ การเช็คว่ามีชื่อซ้ำกันหรือไม่ (ชื่อ login)
ของผมหน้าAdminSave.php คำสั่งinsert into อยู่ด้านบน <html>
<head>
<title>....</title>
ผมเลยไม่เข้าใจในการเขียนคำสั่งเช็คเเละไม่สามารถใช้คำสั่งปริ้นได้ ในหน้าsave จะเเสดงข้อความ"บันทึกข้อมูลเรียบร้อยแล้วครับ" อยู่
ผมต้องแทรกคำสั่ง เช็คชื่อซ้ำไว้ตรงไหนคับ หลัง"submit"ในหน้า Admin.php หรือว่า บน insert into ในหน้าAdminSave.php
เเละเขียนอย่างไรคับ ผมลองมาหลายครั้งเเต่ไม่ได้เลยคับ จนปัญญา ขอท่านผู้รู้ช่วยที่คับ ขอบคุณคับ
___________Admin.php____
Code (PHP)
<table width="668" height="19" border="0" cellpadding="1" cellspacing="1">
<form method="post" action="AdminSave.php" name="webFormprd" onSubmit="return checkprd()">
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">รหัสผู้จัดการ :</font></div></td>
<td><font size="3">
<?
$sql_numcode="select useradminid AS maxID from useradmin ORDER by LENGTH(useradminid) desc, useradminid desc LIMIT 1";
$db_queryr=mysql_db_query($db,$sql_numcode);
$result_numcode=mysql_fetch_array($db_queryr);
$num_rows_code = $result_numcode['maxID'];
$num_rows_code = str_replace("US00", "", $num_rows_code);
$run_number = $num_rows_code+1;
echo "<font size=2 color=#FF0000><b>US00$run_number</b></font><input type=hidden name=useradminid value='US00$run_number'>";
?>
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="160"><div align="right"><font size="2">ชื่อผู้จัดการ :</font></div></td>
<td width="501"><font size="3">
<input name="name" type="text" class="input" size="30">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">ที่อยู่
:</font></div></td>
<td><label for="address"></label>
<textarea name="address" cols="50" rows="5" class="input" id="address"></textarea></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">เบอร์โทรศัพท์:</font></div></td>
<td><font size="3">
<input name="phone" type="text" class="input" id="phone" size="30" maxlength="15">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">ชื่อผู้ใช้ระบบ :</font></div></td>
<td><font size="3">
<input name="useradmin" type="text" class="input" id="useradmin" size="30" maxlength="15">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="right"><font size="2">รหัสผ่าน :</font></div></td>
<td><font size="3">
<input name="passadmin" type="text" class="input" id="passadmin" size="30" maxlength="15">
</font></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td><input name="submit" type="submit" class="a14-2" value="ตกลง" > </td>
</tr>
</form>
</table>
______________AdminSave.php___________
Code (PHP)
<?
@session_start();
ob_start();
$useradmin = $_SESSION["useradmin"];
if(empty($useradmin))
{
echo "<script>alert('หน้านี้จำกัดเฉพาะ Admin เท่านั้น');history.back();</script>";
exit();
}
require_once "../include/tdate.php";
require_once "../include/connect.php";
require_once "../include/connectdb.php";
$passadmin_md5 = md5($_POST[passadmin]);
mysql_query("INSERT INTO useradmin (id,useradminid, name,address,phone,useradmin,passadmin) values('', '$_POST[useradminid]','$_POST[name]','$_POST[address]','$_POST[phone]','$_POST[useradmin]','$passadmin_md5')") or die ("Cannot Add Database");
?>
<html>
<head>
<title>:: <? echo "$headtxt_web"; ?> ::</title>
.....**คำสั่งไม่สำคัญผมตัดออกนะคับ
<div align="center"><br>
<br>
<font color="#990000" size="3">บันทึกข้อมูลเรียบร้อยแล้วครับ<br>
<br>
</font><font color="#003366" size="3"><font color="#990000"><font color="#000066">ต้องการบันทึกข้อมูลต่อหรือไม่</font><br>
<br>
<a href="Admin.php">ข้อมูลผู้จัดการ</a> | <a href="Main.php">กลับหน้าเมนูหลัก</a></font></font><font size="3"><br>
</font><br>
<br>
</div>
Tag : PHP, MySQL, CakePHP
|
|
|
|
|
|
Date :
2013-04-23 18:44:19 |
By :
donkey |
View :
698 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<?
@session_start();
ob_start();
$useradmin = $_SESSION["useradmin"];
if(empty($useradmin))
{
echo "<script>alert('หน้านี้จำกัดเฉพาะ Admin เท่านั้น');history.back();</script>";
exit();
}
require_once "../include/tdate.php";
require_once "../include/connect.php";
require_once "../include/connectdb.php";
$sql = "select count(*) as cnt from useradmin ";
$sql .= "where useradmin='".$_POST[useradmin]."' ";
$rs = mysql_query($sql);
$checkUser = mysql_result($rs, 0, 0 );
if($checkUser != 0){
echo "<script>alert('มี Username นี้แล้วในระบบ');history.back();</script>";
exit();
}
else{
$passadmin_md5 = md5($_POST[passadmin]);
mysql_query("INSERT INTO useradmin (id,useradminid, name,address,phone,useradmin,passadmin) values('', '$_POST[useradminid]','$_POST[name]','$_POST[address]','$_POST[phone]','$_POST[useradmin]','$passadmin_md5')") or die ("Cannot Add Database");
}
?>
<html>
<head>
<title>:: <? echo "$headtxt_web"; ?> ::</title>
.....**คำสั่งไม่สำคัญผมตัดออกนะคับ
<div align="center"><br>
<br>
<font color="#990000" size="3">บันทึกข้อมูลเรียบร้อยแล้วครับ<br>
<br>
</font><font color="#003366" size="3"><font color="#990000"><font color="#000066">ต้องการบันทึกข้อมูลต่อหรือไม่</font><br>
<br>
<a href="Admin.php">ข้อมูลผู้จัดการ</a> | <a href="Main.php">กลับหน้าเมนูหลัก</a></font></font><font size="3"><br>
</font><br>
<br>
</div>
|
|
|
|
|
Date :
2013-04-23 19:10:24 |
By :
thep |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้เเล้วคับ ขอบคุณ คุณ thep มากๆๆคับ +1
|
|
|
|
|
Date :
2013-04-23 19:29:02 |
By :
donkey |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|