|
|
|
มีปัญหาเกี่ยวกับ โค้ด ส่ง password เเบบ random ที่ส่งเข้าเมล์อ่ะ ว่าเขียนเเบบไหน ช่วยหน่อยน่ะครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
ob_start();
include("Includes/root.inc.php");
include("Includes/config.inc.php");
include("Class/func_class.class.php");
if( $_GET[Systems] == "SaveData" && $_POST[TxtUsername] != "" && $_POST[cboPrefaceName] != "" && $_POST[TxtTeacherFirstname] != "" && $_POST[TxtLastNameTeacher] != "" && $_POST[TxtBirthDay] != "" && $_POST[TxtIdcard] != "" && $_POST[TxtAddressTeacher] != ""&& $_POST
[TxtEmail] != "" && $_POST[TxtPhoneTeacher] != "" && $_POST[CboFaculity] != "" && $_POST[CboPosition] != "" && $_POST[CboAcademic] != "") {
if($_POST[HdnTeacherid] == ""){
// Insert Into
if(NumRecode("SELECT * FROM teacher WHERE Teacher_username='".$_POST[TxtUsername]."' ") == 0){
// Add ได้
$Password=random_password(5);
$DateTimeRegister = date("Y-m-d H:i:s");
$this <- mysql_query("INSERT INTO teacher(Teacher_username,Teacher_ele,Teacher_firstname,Teacher_lastname,Teacher_birthday,Teacher_address,
Teacher_idcard,Teacher_tel,Teacher_email,Faculity_id, Position_id,Academic_degree,Password) VALUES ('".$_POST[TxtUsername]."','".$_POST[cboPrefaceName]."','".$_POST[TxtTeacherFirstname]."' ,'".$_POST[TxtLastNameTeacher]."','".$_POST[TxtBirthDay]."','".$_POST[TxtAddressTeacher]."', '".$_POST[TxtIdcard]."','".$_POST[TxtPhoneTeacher]."','".$_POST[TxtEmail]."','".$_POST[CboFaculity]."' ,'".$_POST[CboPosition]."','".$_POST[CboAcademic]."','".base64_encode(base64_encode($Password))."')");
echo "<script language=\"javascript\">alert('บันทึกข้อมูลเป็นที่เรียบร้อยเเล้ว'); </script>";
echo "<script language=\"javascript\">window.location.href='System_Teacher_Manage.php';</script>";
// ส่วน ของ e-mail
$strTo = $_POST["TxtEmail"];
$strSubject = "Test Send Email";
$strHeader = "From: Mr.Weerachai Nukitram<[email protected]>\nReply-To: [email protected]";
$strMessage = "My Body & My Description";
$flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader);// @ = No Show Error //
if($flgSend)
{
echo "Email Sending.";
}
else
{
echo "Email Can Not Send.";
}
//echo "1";
}else{
// ส่วนของ e-mail
// Add ไม่ได้ เนื่องจากข้อมูลซ้ำ
echo "<script language=\"javascript\">alert('บันทึกข้อมูลไม่ได้เนื่องจาก Username ซ้ำในฐานข้อมูล'); </script>";
}
}else{
// Update
$this <- mysql_query("UPDATE teacher SET Teacher_firstname='".$_POST[TxtTeacherFirstname]."',Teacher_lastname='".$_POST[TxtLastNameTeacher]
."',Teacher_address='".$_POST[TxtAddressTeacher]."',Teacher_tel='".$_POST[TxtPhoneTeacher]."',Teacher_email='".$_POST[TxtEmail]."'WHERE Teacher_id='".$_POST[HdnTeacherid]."'");
echo "<script language=\"javascript\">alert('บันทึกการแก้ไขข้อมูลเป็นที่เรียบร้อยเเล้ว'); </script>";
echo "<script language=\"javascript\">window.location.href='System_Teacher_Manage.php';</script>";
$_GET[Systems] = "ShowData";
$_GET[Teacher_id] = $_POST[HdnTeacherid];
}
}
if($_GET[Systems] == "ShowData" && (isset($_GET[Teacher_id]) && $_GET[Teacher_id] != "")){
$sql_show = "SELECT * FROM teacher WHERE Teacher_id='".$_GET[Teacher_id]."'";
$EditTeacherEle= Resulte("$sql_show","Teacher_ele");
$EditTeacherFirstName = Resulte("$sql_show","Teacher_firstname");
$EditTeacherLastname = Resulte("$sql_show","Teacher_lastname");
$EditTeacherBirthday = Resulte("$sql_show","Teacher_birthday");
$EditIdcard = Resulte("$sql_show","Teacher_idcard");
$EditTeacherAddress = Resulte("$sql_show","Teacher_address");
$EditTeacherTel = Resulte("$sql_show","Teacher_tel");
$EditTeacheremail = Resulte("$sql_show","Teacher_email");
$EditTeacherFaculity = Resulte("$sql_show","Faculity_id");
$EditTeacherPosition = Resulte("$sql_show","Position_id");
$EditTeacherAcademic = Resulte("$sql_show","Academic_degree");
echo $EditTeacherPassword = base64_decode(base64_decode(Resulte("$sql_show","Password")));
// $EditTeacherPassword = base64_decode(base_decode(Resulte("$sql_show","Teacher_username")));
}
function std_ele_cbo($ele){
echo "<option value='0'>--------กรุณาเลือก----------</option>";
$std_ele_array=array("นาย","นาง","นางสาว","อื่นๆ");
foreach ($std_ele_array as $key){
echo "<option value='$key'";
if ( $ele == $key ) { echo " selected"; }
echo ">" . $key . "</option>";
}
}
function Teacher_Academic_degree($Academic_degree){
echo"<option value='0'>--------กรุณาเลือก----------</option>";
$Teacher_Academic_degree_array=array("ไม่มีวุฒิการศึกษา","ประถมศึกษา","'ม.3","ม.6 หรือ ปวช.","ปวส./อนุปริญญา","ปริญญาตรี","ประกาศนีบัตรบัณฑิต","ปริญญาโท","ปริญญาเอก");
foreach ($Teacher_Academic_degree_array as $key){
echo "<option value='$key'";
if ($Academic_degree == $key) {echo " selected"; }
echo ">" . $key . "</option>";
}
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>ข้อมูลครู</title>
<script type="text/javascript" language="javascript" src="JS/func_Center.scripts.js"></script>
<script type="text/javascript" language="javascript" src="JS/func_KeyPress.js"></script>
<script type="text/javascript" language="javascript">
function checkID(id) {
if(id.length != 13) return false;
for(i=0, sum=0; i < 12; i++)
sum += parseFloat(id.charAt(i))*(13-i);
if((11-sum%11)%10!=parseFloat(id.charAt(12))) return false;
return true;
}
function isEmail(str) {
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}
function ChkDataRegister(){
var TxtUsername = document.getElementById('TxtUsername').value;
var cboPrefaceName = document.getElementById('cboPrefaceName').value;
var TxtTeacherFirstname = document.getElementById('TxtTeacherFirstname').value;
var TxtLastNameTeacher = document.getElementById('TxtLastNameTeacher').value;
var TxtBirthDay = document.getElementById('TxtBirthDay').value;
var TxtIdcard = document.getElementById('TxtIdcard').value;
var TxtAddressTeacher = document.getElementById('TxtAddressTeacher').value;
var TxtEmail = document.getElementById('TxtEmail').value;
var TxtPhoneTeacher = document.getElementById('TxtPhoneTeacher').value;
var CboFaculity = document.getElementById('CboFaculity').value;
var CboPosition = document.getElementById('CboPosition').value;
var CboAcademic = document.getElementById('CboAcademic').value;
if(TxtUsername == "" || cboPrefaceName == 0 || TxtTeacherFirstname == "" || TxtLastNameTeacher == "" || TxtBirthDay == "" || (TxtIdcard == "" && TxtIdcard.length < 13) ||TxtAddressTeacher == "" || TxtEmail == "" || TxtPhoneTeacher == "" || CboFaculity == 0 || CboPosition == 0 || CboAcademic == 0){
alert('กรุณาระบุข้อมูล !!!');
}else if(!checkID(TxtIdcard)){
alert("รหัสบัตรประชาชนไม่ถูกต้อง !!!");
return false;
}else if (!isEmail(TxtEmail)) {
alert("รูปแบบของ อีเมลล์ ไม่ถูกต้อง !!!");
return false;
}else{
return true;
}
}
function CancelDataRegister(){
document.getElementById('TxtUsername').value = "";
document.getElementById('cboPrefaceName').value = "0";
document.getElementById('TxtTeacherFirstname').value = "";
document.getElementById('TxtLastNameTeacher').value = "";
document.getElementById('TxtBirthDay').value = "";
document.getElementById('TxtAddressTeacher').value = "";
document.getElementById('TxtEmail').value = "";
document.getElementById('TxtIdcard').value = "";
document.getElementById('TxtPhoneTeacher').value = "";
document.getElementById('CboFaculity').value = "0";
document.getElementById('CboPosition').value = "0";
document.getElementById('CboAcademic').value = "0";
}
window.onload = function() {
var Now = new Date();
var Year = Now.getFullYear();
var TotalYear = Year - 1945;
MyDatePickerB = new PBBDatePicker($('txtBirthday'), {
dateFormat : 'Y-m-d',
rangeYear: {'min': new Date().getFullYear()-TotalYear, 'max': new Date().getFullYear()+1 },
iconImg : 'images/icon_cal.png',
onShow: function(picker){
picker.effects({duration: 500, transition: Fx.Transitions.quadInOut}).custom({'opacity': [0, 0.8]});
}
});
}
</script>
<link href="../css/css_datepicker.css" rel="stylesheet" type="text/css">
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>
<body>
<table width="500" border="0" align="center">
<tr>
<td><form action="Add_teacher.php?Systems=SaveData"method="post" name="frmteacher" id="frmteacher" onSubmit="return ChkDataRegister();">
<table width="500" border="1" align="left" cellpadding="4" cellspacing="0" bordercolor="#FDBF64">
<tr>
<td colspan="2" bgcolor="#FF6338"><table width="100%" border="0">
<tr>
<th width="87%" align="left" valign="middle" class="text_white_14"><img src="images/icon_status.disable.gif" width="18" height="14"><span class="text_white_18">ข้อมูลครู</span></th>
<td width="13%"><img src="images/menu-bg.gif" width="63" height="22"></td>
</tr>
</table></td>
</tr>
<tr>
<th width="41%" height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">รหัสคุณครู</th>
<td width="59%" height="30" bgcolor="#FEDAA5"><input name="TxtUsername" type="text" class="textboxW200px" id="TxtUsername" maxlength="5" onKeyPress="checkvalueEng_Number();" >
<strong>
<input name="HdnTeacherid" type="hidden" id="HdnTeacherid" value="<?=$_GET[Teacher_id];?>">
</strong></td></tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">คำนำหน้าชื่อ</th>
<td height="30" bgcolor="#FEDAA5"><label>
<select name="cboPrefaceName" class="textboxW150px" id="cboPrefaceName">
<? $this <-std_ele_cbo("$EditTeacherEle"); ?>
</select>
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">ชื่อ</th>
<td height="30" bgcolor="#FEDAA5"><label>
<input name="TxtTeacherFirstname" type="text" class="textboxW200px" id="TxtTeacherFirstname" value="<?=$EditTeacherFirstName;?>" maxlength="50">
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">นามสกุล</th>
<td height="30" bgcolor="#FEDAA5"><label>
<input name="TxtLastNameTeacher" type="text" class="textboxW200px" id="TxtLastNameTeacher" value="<?=$EditTeacherLastname;?>" maxlength="50">
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">วัน-เดือน-ปีเกิด</th>
<td height="30" bgcolor="#FEDAA5"><label>
<input name="TxtBirthDay" type="text" class="textboxW200px" id="TxtBirthDay" value="<?=$EditTeacherBirthday;?>" maxlength="10" onKeyPress="checkvalueNum();">
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">รหัสประจำตัวประชาชน</th>
<td height="30" bgcolor="#FEDAA5"><input name="TxtIdcard" type="text" class="textboxW200px" id="TxtIdcard" onKeyPress="checkvalueNum();" value="<?=$EditIdcard;?>" maxlength="13" >
</td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">ที่อยู่ </th>
<td bgcolor="#FEDAA5"><label>
<textarea name="TxtAddressTeacher" class="textboxW250X100px" id="TxtAddressTeacher"><?=$EditTeacherAddress;?></textarea>
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">E-mail </th>
<td height="30" bgcolor="#FEDAA5"><span class="text_white_14">
<input name="TxtEmail" type="text" class="textboxW200px" id="TxtEmail" value="<?=$EditTeacheremail;?>" maxlength="100" onKeyPress="checkvalueEngEmail();" onFocus="isEmail">
</span></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">เบอร์โทรศัพท์ติดต่อ</th>
<td height="30" bgcolor="#FEDAA5"><label><span class="text_white_14">
<input name="TxtPhoneTeacher" type="text" class="textboxW200px" id="TxtPhoneTeacher" value="<?=$EditTeacherTel;?>" maxlength="15" onKeyPress="checkvalueNum();">
</span></label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">กลุ่มสาระวิชา</th>
<td height="30" bgcolor="#FEDAA5"><label>
<select name="CboFaculity" class="textboxW250px" id="CboFaculity">
<? $this <- listmenu_sql("SELECT Faculity_id,Faculity_name FROM faculity WHERE status='Y' AND statusdel='N' ORDER BY Faculity_name ASC","");?>
</select>
</label></td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">ตำเเหน่งทางการศึกษา</th>
<td height="30" bgcolor="#FEDAA5"><select name="CboPosition" class="textboxW250px" id="CboPosition">
<?
$this <- listmenu_sql("SELECT Position_id,Position_name FROM position_education WHERE status='Y' AND statusdel='N' ORDER BY Position_name ASC","");
?>
</select> </td>
</tr>
<tr>
<th height="30" align="left" valign="middle" bgcolor="#F88D4E" class="text_white_14">วุฒิทางการศึกษาสูงสุด</th>
<td height="30" bgcolor="#FEDAA5"><select name="CboAcademic" class="textboxW200px" id="CboAcademic">
<? $this <-Teacher_Academic_degree("$Academic_degree"); ?>
</select> </td>
</tr>
<tr>
<td bgcolor="#F88D4E"> </td>
<td height="30" bgcolor="#FEDAA5"><label>
<input name="btnsave" type="submit" class="button_normal" id="btnsave" value="บันทึก">
</label>
<label>
<input name="btncancel" type="reset" class="button_normal" id="btncancel" value="ยกเลิก" onClick="CancelDataRegister();">
<input name="Button" type="button" class="button_normal" value="Back"
onClick="window.location.href='System_Teacher_Manage.php?Systems=ShowData&Teacher_id=<?=$resulte[Teacher_id];?>';">
</label></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FF6338"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
<?
mysql_close();
ob_end_flush();
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-12-09 20:21:40 |
By :
juntaro |
View :
1209 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
function random_password($len)
{
srand((double)microtime()*10000000);
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$ret_str = "";
$num = strlen($chars);
for($i = 0; $i < $len; $i++)
{
$ret_str.= $chars[rand()%$num];
$ret_str.="";
}
return $ret_str;
}
// echo random_password(8);
$passw = random_password(7);
|
|
|
|
|
Date :
2011-07-26 22:11:42 |
By :
thaicreate |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|