|
|
|
มาช่วยตอบบันหาไห้ด้วยนะคะ คือว่ามีหน้า add ข้อมูล..เวลาไม่ได้ก็อกข้อมูลอะไรลง textbox แต่ไปกด save เลีย,มันฟ้องออกมาว่า มีข้อมูลนี้แล้ว |
|
|
|
|
|
|
|
ช่วยดู code ไห้ด้วยคะ
ไม่รู้จะไปกำนดต่งไหนคะ ไห้มันตวดว่า ถ้าไม่มีกานป้อน เถืงจะกด save ก่อไม่ได้คะ
มีอยู่ 2 code
1...formadd.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
font-family: Saysettha OT;
font-size: 14px;
color: #000;
}
body {
background-color:#CCC;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style25 {
font-size: 14px;
font-family: Saysettha OT;
}
.style26 {
font-size: 14px;
font-family: Saysettha OT;
color: #F00;
}
.style19 {font-size: 16px}
.style15 { font-size: 14px;
color: #0000FF;
font-family: "Saysettha OT";
}
-->
</style></head>
</head>
<body>
<form id="Add" name="Add" method="post" action="phpMySqlAddSave.php" onsubmit="return chkSubmit();"
onSubmit="JavaScript:return check_from();">
<table width="770" height="500" border="1" bordercolor="#990033">
<tr>
<td width="500" height="100" bgcolor="#003333">
<p>
<div align="center"><font size="3" color="#FFFFFF">Short code:</font>
<label for="textfield5"></label>
<input name="textShortcodeName" type="text" id="textShortcodeName" size="15" />
</div>
</p>
<p> <font size="3" color="#FFFFFF">ຊື່ບໍລິສັດ :</font>
<label for="textfield1"></label>
<input type="text" name="textCompany" id="textCompany" />
</p>
<p><font size="3" color="#FFFFFF">Efect time:</font>
<label for="textfield2"></label>
<input type="text" name="textEffectTime" id="textEffectTime" />
</p>
<p>
<font size="4" color="#FFFFFF">Expire time:</font>
<label for="textfield3"></label>
<input type="text" name="textExpireTime" id="textExpireTime" />
</p>
<p>
<font size="4" color="#FFFFFF">Tel : </font>
<label for="textfield"></label>
<input type="text" name="textTel" id="textTel" />
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>
<font ><input type="submit" name="button4" id="button4" value="ເພີ່ມຂໍ້ມູນ" onclick="return check_from()"style="width:100px;height:30px" /></font>
<font><input type="reset" name="reset" id="reset" value="ຍົກເລີກ" style="width:100px;height:30px"></font>
</p>
<p></p>
<p> </p>
</td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
<script language="JavaScript">
function chkSubmit()
{
if(isNaN(document.Add.textShortcodeName.value))
{
alert('Please input shortcode Number only.');
return false;
}
}
</script>
<script type="text/javascript">
function check_from()
{
if(document.Add.textShortcodeName.value=="")
{
alert("Please enter Shortcode");
document.form1.textShortcodeName.focus();
return false;
}
if(document.Add.textCompany.value=="")
{
alert("Please enter Company name");
document.Add.textCompany.focus();
return false;
}
if(document.Add.textEffectTime.value=="")
{
alert("Please enter EffectTime");
document.Add.textEffectTime.focus();
return false;
}
if(document.Add.textExpireTime.value=="")
{
alert("Please enter ExpireTime");
document.Add.textExpireTime.focus();
return false;
}
if(document.Add.textTel.value=="")
{
alert("Please enter Tel number");
document.Add.textTel.focus();
return false;
}
}
</script>
2...phpMySqlAddSave.php
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$SQL = "select * from shortcode where ShortcodeName='".$_POST["textShortcodeName"]."' ";
$Query = mysql_query($SQL);
$Result = mysql_fetch_array($Query);
if($Result)
{
echo "<script language='javascript'>alert('มีแล้ว'); history.back(); </script>";
exit;
}
else {
$strSQL = "";
$strSQL = "INSERT INTO shortcode";
$strSQL .="(ShortcodeName,Company,Effect_time,Expire_time,Tel) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["textShortcodeName"]."','".$_POST["textCompany"]."','".$_POST["textEffectTime"]."' ";
$strSQL .=",'".$_POST["textExpireTime"]."','".$_POST["textTel"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
} }
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-05-30 12:09:23 |
By :
Cat |
View :
891 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body,td,th {
font-family: Saysettha OT;
font-size: 14px;
color: #000;
}
body {
background-color:#CCC;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style25 {
font-size: 14px;
font-family: Saysettha OT;
}
.style26 {
font-size: 14px;
font-family: Saysettha OT;
color: #F00;
}
.style19 {font-size: 16px}
.style15 { font-size: 14px;
color: #0000FF;
font-family: "Saysettha OT";
}
-->
</style>
</head>
<body>
<form name="Add" method="post" action="phpMySqlAddSave.php" onSubmit="JavaScript:return check_from();">
<table width="770" height="500" border="1" bordercolor="#990033">
<tr>
<td width="500" height="100" bgcolor="#003333">
<p>
<div align="center"><font size="3" color="#FFFFFF">Short code:</font>
<label for="textfield5"></label>
<input name="textShortcodeName" type="text" id="textShortcodeName" size="15" />
</div>
</p>
<p> <font size="3" color="#FFFFFF">ຊື່ບໍລິສັດ :</font>
<label for="textfield1"></label>
<input type="text" name="textCompany" id="textCompany" />
</p>
<p><font size="3" color="#FFFFFF">Efect time:</font>
<label for="textfield2"></label>
<input type="text" name="textEffectTime" id="textEffectTime" />
</p>
<p>
<font size="4" color="#FFFFFF">Expire time:</font>
<label for="textfield3"></label>
<input type="text" name="textExpireTime" id="textExpireTime" />
</p>
<p>
<font size="4" color="#FFFFFF">Tel : </font>
<label for="textfield"></label>
<input type="text" name="textTel" id="textTel" />
</p>
<p>
<font ><input type="submit" name="button4" id="button4" value="ເພີ່ມຂໍ້ມູນ" onclick="return check_from()"style="width:100px;height:30px" /></font>
<font><input type="reset" name="reset" id="reset" value="ຍົກເລີກ" style="width:100px;height:30px"></font>
</p>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function check_from(){
if(document.Add.textShortcodeName.value==""){
alert("Please enter Shortcode");
document.Add.textShortcodeName.focus();
return false;
}
if(isNaN(document.Add.textShortcodeName.value)){
alert('Please input shortcode Number only.');
return false;
}
if(document.Add.textCompany.value==""){
alert("Please enter Company name");
document.Add.textCompany.focus();
return false;
}
if(document.Add.textEffectTime.value==""){
alert("Please enter EffectTime");
document.Add.textEffectTime.focus();
return false;
}
if(document.Add.textExpireTime.value==""){
alert("Please enter ExpireTime");
document.Add.textExpireTime.focus();
return false;
}
if(document.Add.textTel.value==""){
alert("Please enter Tel number");
document.Add.textTel.focus();
return false;
} else {
return true;
}
}
</script>
</body>
</html>
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$SQL = "select * from shortcode where ShortcodeName='".$_POST["textShortcodeName"]."' ";
$Query = mysql_query($SQL);
$Result = mysql_fetch_array($Query);
if($Result){
echo "<script language='javascript'>alert('มีแล้ว'); history.back(); </script>";
exit;
}
$strSQL ="INSERT INTO shortcode (ShortcodeName,Company,Effect_time,Expire_time,Tel) VALUES('".$_POST["textShortcodeName"]."','".$_POST["textCompany"]."','".$_POST["textEffectTime"]."','".$_POST["textExpireTime"]."','".$_POST["textTel"]."')";
$objQuery = mysql_query($strSQL) or die (mysql_error());
if($objQuery){
echo "Save Done.";
} else {
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
|
|
|
|
|
Date :
2012-05-30 13:10:44 |
By :
บังเอิญผ่านมาเห็น |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองรันดู พาสเชื่อมต่อฐานข้อมูล ไม่ผิดนะ
|
|
|
|
|
Date :
2012-05-30 13:11:34 |
By :
บังเอิญผ่านมาเห็น |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|