|
|
|
การใช้ภาษา JavaScript พอ RUN มันขึ้นฟ้อง Error!! Cannot save ^^^^^ |
|
|
|
|
|
|
|
Code (PHP)
<?php
//$hostname = "localhost";
//$username = "root";
//$password = "1234";
$dbname = "mydatabase";
//$conn = mysql_connect( $hostname, $username, $password );
$config = mysql_connect("localhost", "root", "1234");
if ( ! $config )
die ( "ไม่สามารถติดต่อกับ MySQL ได้" );
mysql_select_db ( $dbname, $config )
or die ( "ไม่สามารถเลือกฐานข้อมูล resume ได้" );
mysql_query("SET NAMES UTF8");
if ($_REQUEST["Save1"] != ""){
$strSQL = "INSERT INTO resume ";
$strSQL .= "( IDPersonnel, Pre_IDPrefix, Res_Names, Res_lastName, Res_NamesEng, Res_LdentityCode, Res_Blood, Res_NickName, Res_Sex, Res_Tel, Res_Email, Res_Birthday, Res_Address, Dis_DistrictID, PROVINCE_ID, Res_PostalCode, Bel_BelongID, Res_Duty, Res_Position, Res_DayOperations, Res_Salary, Bos_BossID, Res_IDTheDriver, Res_Educational, Res_Emergency, Res_Father, Res_TelFather, Res_Mather, Res_TelMather) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["IDPersonnel"]."','".$_POST["Pre_IDPrefix"]."','".$_POST["Res_Names"]."' ";
$strSQL .=",'".$_POST["Res_lastName"]."','".$_POST["Res_NamesEng"]."','".$_POST["Res_LdentityCode"]."' ";
$strSQL .=",'".$_POST["Res_Blood"]."','".$_POST["Res_NickName"]."','".$_POST["Res_Sex"]."' ";
$strSQL .=",'".$_POST["Res_Tel"]."','".$_POST["Res_Email"]."','".$_POST["Res_Birthday"]."' ";
$strSQL .=",'".$_POST["Res_Address"]."','".$_POST["PROVINCE_ID"]."','".$_POST["Res_PostalCode"]."' ";
$strSQL .=",'".$_POST["Bel_BelongID"]."','".$_POST["Res_Duty"]."','".$_POST["Res_Position"]."' ";
$strSQL .=",'".$_POST["Res_DayOperations"]."','".$_POST["Res_Salary"]."','".$_POST["Bos_BossID"]."' ";
$strSQL .=",'".$_POST["Res_IDTheDriver"]."','".$_POST["Res_Educational"]."','".$_POST["Res_Emergency"]."' ";
$strSQL .=",'".$_POST["Res_Father"]."','".$_POST["Res_TelFather"]."','".$_POST["Res_Mather"]."' ";
$strSQL .=",'".$_POST["Res_TelMather"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//echo "<script>alert('Save successfully!');</script>";
echo "<script>window.top.window.showResult('1');</script>";
}
else
{
//echo "<script>alert('Error! Cannot save');</script>";
echo "<script>window.top.window.showResult('2');</script>";
}
}
if ($_REQUEST["Edit1"] != ""){
$SQLTXT = "update resume SET IDPersonnel='".$IDPersonnel."', Pre_IDPrefix='".$Pre_IDPrefix."',
Res_Names='".$Res_lastName."', Res_NamesEng='".$Res_NamesEng."', Res_LdentityCode='".$Res_LdentityCode."', Res_Blood='".$Res_Blood."', Res_NickName='".$Res_NickName."', Res_Sex='".$Res_Sex."', Res_Tel='".$Res_Tel."',
Res_Email='".$Res_Email."', Res_Birthday='".$Res_Birthday."', Res_Address='".$Res_Address."',
Dis_DistrictID='".$Dis_DistrictID."', PROVINCE_ID='".$PROVINCE_ID."', Res_PostalCode='".$Res_PostalCode."',
Bel_BelongID='".$Bel_BelongID."', Res_Duty='".$Res_Duty."', Res_Position='".$Res_Position."',
Res_DayOperations='".$Res_DayOperations."', Res_Salary='".$Res_Salary."',Bos_BossID='".$Bos_BossID."',
Res_IDTheDriver='".$Res_IDTheDriver."', Res_Educational='".$Res_Educational."',
Res_Emergency='".$Res_Emergency."',Res_Father='".$Res_Father."', Res_TelFather='".$Res_TelFather."',
Res_Mather='".$Res_Mather."', Res_TelMather='".$Res_TelMather."',where IDPersonnel='".$IDPersonnel."' ";
mysql_query( $SQLTXT, $config )
or die ( "update มีข้อผิดพลาดเกิดขึ้น" ) . mysql_error();
}
mysql_close ( $config );
?>
<html>
<head>
<style type="text/css">
<!--
.style3 {color: #000000}
.style4 {
font-size: 18px;
font-weight: bold;
}
.style10 {font-size: 14px}
body {
background-color: #333333;
background-repeat: repeat;
}
-->
</style>
</head>
<body>
<form action="resume.php" name="From1" id="From1" method="post" target="iframe_target">
<iframe id="iframe_target" name="iframe_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
<script language="JavaScript">
function showResult(result)
{
if(result==1)
{
document.getElementById("divResult").innerHTML = "<font color=green> Save successfully! </font> <br>";
}
else
{
document.getElementById("divResult").innerHTML = "<font color=red> Error!! Cannot save ^^^^^ </font> <br>";
}
}
</script>
<div id="divResult"></div>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<table width="1058" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<th colspan="8"><img src="Images/Untitled-4.gif" width="1060" height="86" /></th>
</tr>
<tr>
<th width="32" height="30"> </th>
<td width="102"> </td>
<td width="163"> </td>
<td colspan="5"> </td>
</tr>
<tr>
<th height="30" colspan="8"> </th>
</tr>
<tr>
<th height="30"> </th>
<td> </td>
<td> </td>
<td width="176"> </td>
<td width="169"> </td>
<td width="322"> </td>
<td width="58"> </td>
<td width="36"> </td>
</tr>
<tr>
<th height="30"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="34"> </th>
<td> </td>
<td><div align="center" class="style4 style10 style10"><span class="style3">รหัสประจำตัวพนักงาน</span></div></td>
<td><input name="IDPersonnel" type="text" class="style10" id="IDPersonnel" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="30"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">คำนำหน้าชื่อ</span></strong></div></td>
<td><span class="style10 style10">
<select name="Pre_IDPrefix" id="Pre_IDPrefix" title="<?php echo $row_re_sh['Pre_IDPrefix']; ?>">
<option value="">เลือก</option>
<option value="1" <?php if (!(strcmp(1, $row_Recordset1['Res_Sex']))) {echo "selected=\"selected\"";} ?>>ชาย</option>
<option value="2" <?php if (!(strcmp(2, $row_Recordset1['Res_Sex']))) {echo "selected=\"selected\"";} ?>>หญิง</option>
</select>
</span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr><th height="35"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ชื่อ</span></strong></div></td>
<td><input name="Res_Names" type="text" class="style10" id="Res_Names" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">สกุล </span></strong></div></td>
<td><input name="Res_lastName" type="text" class="style10" id="Res_lastName" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="36"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ชื่อภาษาอังกฤษ</span></strong></div></td>
<td><input name="Res_NamesEng" type="text" class="style10" id="Res_NamesEng" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">รหัสประจำตัวประชาชน</span></strong></div></td>
<td><input name="Res_LdentityCode" type="text" class="style10" id="Res_LdentityCode" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="33"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ชื่อเล่น</span></strong></div></td>
<td><input name="Res_NickName" type="text" class="style10" id="Res_NickName" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">หมู่โลหิต</span></strong></div></td>
<td><span class="style10 style10">
<select name="Res_Blood" id="Res_Blood">
<option value="0">เลือก</option>
<option value="1">O</option>
<option value="2">A</option>
<option value="3">B</option>
<option value="4">AB</option>
</select>
</span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="32"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">เบอร์โทร</span></strong></div></td>
<td><input name="Res_Tel" type="text" class="style10" id="Res_Tel" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">E-mail</span></strong></div></td>
<td><input name="Res_Email" type="text" class="style10" id="Res_Email" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="31"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">วันเกิด</span></strong></div></td>
<td><input name="Res_Birthday" type="date" class="style10" id="Res_Birthday" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ที่อยู่</span></strong></div></td>
<td><input name="Res_Address" type="text" class="style10" id="Res_Address" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="30"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ตำบล</span></strong></div></td>
<td><span class="style10 style10">
<select name="Dis_DistrictID" id="Dis_DistrictID">
<option value="0">เลือก</option>
<option value="1">บางโกระ</option>
<option value="2">หาดใหญ่</option>
</select>
</span></td>
<td><div align="center" class="style10 style10"><strong>อำเภอ</strong></div></td>
<td><span class="style10 style10">
<label>
<input type="text" name="textfield" id="textfield">
</label>
</span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="31"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">จังหวัด</span></strong></div></td>
<td><input name="PROVINCE_ID2" type="text" class="style10" id="PROVINCE_ID2" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">รหัสไปรษณี</span></strong></div></td>
<td><input name="Res_PostalCode" type="text" class="style10" id="Res_PostalCode" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="30"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">เพศ</span></strong></div></td>
<td><span class="style10 style10">
<select name="Res_Sex" id="Res_Sex">
<option value="0">เลือก</option>
<option value="1">ชาย</option>
<option value="2">หญิง</option>
</select>
</span></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">บัตรประจำตัวผู้ขับขี่</span></strong></div></td>
<td><input name="Res_IDTheDriver" type="text" class="style10" id="Res_IDTheDriver" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="32"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">วันที่เริ่มงาน</span></strong></div></td>
<td><input name="Res_DayOperations" type="date" class="style10" id="Res_DayOperations" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">วุุฒิการศึกษา</span></strong></div></td>
<td><input name="Res_Educational" type="text" class="style10" id="Res_Educational" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="32"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">หัวหน้าผู้ควบคุม</span></strong></div></td>
<td><input name="Bos_BossID" type="text" class="style10" id="Bos_BossID" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">หน้าท</span></strong>ี่</div></td>
<td><input name="Res_Duty" type="text" class="style10" id="Res_Duty" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="33"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">ตำแหน่ง</span></strong></div></td>
<td><input name="Res_Position" type="text" class="style10" id="Res_Position" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">สังกัด</span></strong></div></td>
<td><span class="style10 style10">
<select name="Bel_BelongID" id="Bel_BelongID">
<option value="0">เลือก</option>
<option value="1">สาขารัตภูมิ</option>
<option value="2">สาขาระโนด</option>
<option value="3">สาขาหาดใหญ่</option>
<option value="4">สาขาสงขลา</option>
<option value="5">สาขาควนลัง</option>
<option value="6">สาขาสิงหนคร</option>
</select>
</span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="34"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">เงินเดือน</span></strong></div></td>
<td><input name="Res_Salary" type="text" class="style10" id="Res_Salary"/></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">กรณีฉุกเฉินแจ้ง</span></strong></div></td>
<td><input name="Res_Emergency" type="text" class="style10" id="Res_Emergency" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="33"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">บิดา</span></strong></div></td>
<td><input name="Res_Father" type="text" class="style10" id="Res_Father" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">เบอร์โทรบิดา</span></strong></div></td>
<td><input name="Res_TelFather" type="text" class="style10" id="Res_TelFather" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="37"> </th>
<td> </td>
<td><div align="center" class="style10 style10"><strong><span class="style3">มารดา</span></strong></div></td>
<td><input name="Res_Mather" type="text" class="style10" id="Res_Mather" /></td>
<td><div align="center" class="style10 style10"><strong><span class="style3">เบอร์โทรมารดา</span></strong></div></td>
<td><input name="Res_TelMather" type="text" class="style10" id="Res_TelMather" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="submit" name="Save1" value="บันทึก" id="Save1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<th height="38"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-11-21 20:25:23 |
By :
Nom |
View :
916 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไมไม่ใส่ or die(mysql_error());
031.$objQuery = mysql_query($strSQL) or die(mysql_error()."<br />$strSQL");
032.if($objQuery)
ใส่แล้วจะเห็นครับว่าผิดตรงไหน
|
|
|
|
|
Date :
2012-11-21 20:53:46 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รันแล้วแสดง "<script>alert('Error! Cannot save');</script>";
ไม่น่าเกี่ยวกับ javascript น่ะครับ เพราะมันมีเงือนไขแบบข้างล่าง
$objQuery = mysql_query($strSQL);
if($objQuery){
.......
}
คุมมันเอาไว้แล้ว แสดงว่า query คุณรันไม่ผ่านมากกว่าครับ
|
|
|
|
|
Date :
2012-11-21 20:58:18 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|