|
 |
|
ขอลบกวนพี่ฯอีกคะ คือว่าหนู add ข้อมูลลง table คะแต่ก็มีกานตรวดสอบก่อนแล้วนะคะว่า ถ้าข้อมูนนั้นมีแล้วก็ add เข้าไม่ได้อีก แต่ว่า....มันยัง add เข้าไปได้อยู่เลีย |
|
 |
|
|
 |
 |
|
คือว่าหนูกำหนดไห้เป็น ฟีวไห้เป็น ShortcodeName varchar(8) utf8_general_ci เมี่อก็อกข้อมูนเข้าไปภ้าตัวเลกที่ไม่เภืง 8 ตัว (Ex 12345678) ก็จะมีกานตรวดว่ามีหลืยังถ้ามีแล้วก็จะฟ้องอออกมาว่า มีแล้ว ..แต่ถ้าตัวเลกมากกว่า 8 ตัวอักสอน (Ex 123456789) ก็อกเข้าไปมันจะไม่ตรวดคะ คือว่า ก็อกช้ำกันเป็น 10รอบก็ เข้า table หมดเลียคะ.หนูควนแก้ต่รงไหนคะ ช่วยอะทิบายไห้เข้าใจด้วยคะ เพาะว่าเวลาหนูเอามาโชหนูจะไช้ text เก็บคะ ถ้ามันมีมากกว่า 1มันก็ออกมายายกันเต็มจอเลีย สะนั้นหนูต้องกานแค่ข้อมูลดฯว ห้ามช้ำกันเด็ดขาด
************ขอบใจหลายฯฯพี่น้อง****************
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");
mysql_query("SET NAMES UTF8");
$SQL = "select * from shortcode where ShortcodeName='".$_POST["textShortcodeName"]."' "; /*ส่วนที่กวดสอบว่ามีข้อมูลที่จะป้อนเข้าไปไหม่หลืยัง ภ้าบ่อมี จี่งสามาด add ได้ แต่ถ้ามีแล้วบ่อไห้ adลงอีก.*/
$Query = mysql_query($SQL);
$Result = mysql_fetch_array($Query);
$pp=$Result["ShortcodeName"];
if(isset($pp))
{
echo "<script language='javascript'>alert('มีแล้ว'); history.back(); </script>";
exit;
}
else {
$strSQL = "";
$strSQL = "INSERT INTO shortcode";
$strSQL .="(ShortcodeName,Company,Effect_time,Expire_time,Reference,Price,Tax,Share_ETL,Share_partner,Tel,Note) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["textShortcodeName"]."','".$_POST["textCompany"]."','".$_POST["textEffectTime"]."' ";
$strSQL .=",'".$_POST["textExpireTime"]."','".$_POST["textRefer"]."' ,'".$_POST["textPrice"]."','".$_POST["textTax"]."','".$_POST["textETL"]."', '".$_POST["textPart"]."','".$_POST["textTel"]."','".$_POST["textNote"]."') ";
$objQuery = mysql_query($strSQL)or die (mysql_error());
if($objQuery)
{
echo "<script language='javascript'>alert('Save Done'); window.location = 'win3.php'; </script>";
exit;
}
else
{
echo "Error Save [".$strSQL."]";
} }
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-06-06 09:15:38 2012-06-06 09:56:30
|
 |
 |
 |
 |
Date :
2012-06-06 09:14:47 |
By :
Cat |
View :
960 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้ substr() ดูครับ
Code (PHP)
$SQL = "select * from shortcode where ShortcodeName='".substr($_POST["textShortcodeName"],0,8)."' ";
|
 |
 |
 |
 |
Date :
2012-06-06 10:55:23 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2012-06-06 10:55:23
รายละเอียดของการตอบ ::
... คะขอบใจ แต่ถ้าหาก add ช้ำข้อมูลเดีมไม่ได้แล้ว กัลหน้า edit ละคะ
Ex: มีคนเข้ามาหน้า edit from แล้ว แปง shortcode ไห้มันเหมือนกับ shortcode ที่มีอยู่แล้ว สะนั้นมันก็ต้องมี ข้อมูลช้อนกันเหมือนเดีม หนูควนจะเพี่มอะไรไหมคะ
อยากไห้หน้า edit มันตรวดดูว่าข้อมูลที่จะแปงมันช้ำกับข้อมูลใน table นั้นลืบป่าว
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");
$pp=$Result["ShortcodeName"];
/*if(isset($pp))
{
echo "<script language='javascript'>alert('มีแล้ว'); history.back(); </script>";
exit;
}
else{*/
$strSQL = "UPDATE shortcode SET ";
$strSQL .="ShortcodeName = '".$_POST["txtShortcode"]."' ";
$strSQL .=",Company = '".$_POST["txtCompany"]."' ";
$strSQL .=",Effect_time = '".$_POST["txtEffectTime"]."' ";
$strSQL .=",Expire_time = '".$_POST["txtExpireTime"]."' ";
$strSQL .=",Reference = '".$_POST["txtReference"]."' ";
$strSQL .=",Price = '".$_POST["txtPrice"]."' ";
$strSQL .=",Tax = '".$_POST["txtTax"]."' ";
$strSQL .=",Share_ETL = '".$_POST["txtShareETL"]."' ";
$strSQL .=",Share_partner = '".$_POST["txtSharepartner"]."' ";
$strSQL .=",Tel = '".$_POST["txtTel"]."' ";
$strSQL .=",Note = '".$_POST["txtNote"]."' ";
$strSQL .="WHERE ShortcodeName = '".$_GET["ShortID"]."' " ;
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "<script language='javascript'>alert('แปงข้อมูลเรียบร้อยแล้ว'); window.location = 'win3.php'; </script>";
}
else
{
echo "Error Save [".$strSQL."]";
}
/*}*/
mysql_close($objConnect);
?>
</body>
</html>.....
|
 |
 |
 |
 |
Date :
2012-06-06 11:13:10 |
By :
Cat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันที่จริงถ้าเป็น Key พวกนี้ไม่ควรแก้ไขครับ แต่ถ้าจะแก้ไขก็ตรวจสอบเหมือนการเพิ่มเลยครับ
|
 |
 |
 |
 |
Date :
2012-06-06 11:28:35 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 3 เขียนโดย : mr.win เมื่อวันที่ 2012-06-06 11:28:35
รายละเอียดของการตอบ ::
... หนูเพี่มแบบนี้ทำไหมมันไม่ออกคะ ช่วยตรวดไห้ด้วยคะ
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 = '".$_GET["ShortID"]."' " ;
$obgsql = mysql_query($sql);
$num = mysql_num_rows($objsql);
if($num >0){
echo "<script>alert('have');</script>";
exit();
}
else {
$strSQL = "UPDATE shortcode SET ";
$strSQL .="ShortcodeName = '".$_POST["txtShortcode"]."' ";
$strSQL .=",Company = '".$_POST["txtCompany"]."' ";
$strSQL .=",Effect_time = '".$_POST["txtEffectTime"]."' ";
$strSQL .=",Expire_time = '".$_POST["txtExpireTime"]."' ";
$strSQL .=",Reference = '".$_POST["txtReference"]."' ";
$strSQL .=",Price = '".$_POST["txtPrice"]."' ";
$strSQL .=",Tax = '".$_POST["txtTax"]."' ";
$strSQL .=",Share_ETL = '".$_POST["txtShareETL"]."' ";
$strSQL .=",Share_partner = '".$_POST["txtSharepartner"]."' ";
$strSQL .=",Tel = '".$_POST["txtTel"]."' ";
$strSQL .=",Note = '".$_POST["txtNote"]."' ";
$strSQL .="WHERE ShortcodeName = '".$_GET["ShortID"]."' " ;
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "<script language='javascript'>alert('แปงข้อมูลเรียบร้อยแล้ว'); window.location = 'win3.php'; </script>";
}
else
{
echo "Error Save [".$strSQL."]";
}
}
mysql_close($objConnect);
?>
</body>
</html>......
|
 |
 |
 |
 |
Date :
2012-06-06 13:03:32 |
By :
Cat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|