|
 |
|
ข้อมูลมันไม่จัดเก็บลง database ทำมานานงง มากมาย รบกวนช่วยตอบทีคะ PHP, Ms SQL Server 2005 |
|
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>test</title>
</head>
<body>
<form action="AddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID" size="5"></div></td>
<td><input type="text" name="txtName" size="20"></td>
<td><input type="text" name="txtEmail" size="20"></td>
<td><div align="center"><input type="text" name="txtCountryCode" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget" size="5"></td>
<td align="right"><input type="text" name="txtUsed" size="5"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
พอจะจัดเก็บข้อมูลลงดาต้าเบสแล้ว มันไม่มีอะไรเกิดขึ้นเลย ข้อมูลก้อไม่ลงดาต้าเบส งงมากรบกวนถามผุ้รู้หนอ่ยคะ
Code (PHP)
<html>
<head>
<title>test</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","sa","***") or die("Error Connect to Database");
$objDB = mysql_select_db("hr_Employee");
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."' ";
$strSQL .=",'".$_POST["txtCountryCode"]."','".$_POST["txtBudget"]."','".$_POST["txtUsed"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
Tag : PHP, Ms SQL Server 2005

|
|
 |
 |
 |
 |
Date :
2011-03-09 11:10:21 |
By :
อยากรู้ |
View :
924 |
Reply :
12 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บอกตามตรงผมก็ไม่ค่อยแม่นครับ ยิ่งเจอ ลักษณะนี้
Code (PHP)
$strSQL .="('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."' ";
$strSQL .=",'".$_POST["txtCountryCode"]."','".$_POST["txtBudget"]."','".$_POST["txtUsed"]."') ";
มีโอกาสพิมพ์ผิดง่าย(สำหรับผมนะ)
ลองเพิ่มนี้ดูครับว่าส่งค่ามาไหม
Code (PHP)
<?
// เพิ่มเข้าไป แล้วลองสั่งให้แสดงค่าดูว่ามีไหมครับ
$txtCustomerID=$_POST["txtCustomerID"];
$txtName=$_POST["txtName"]
$txtEmail=$_POST["txtEmail"]
$txtCountryCode=$_POST["txtCountryCode"]
$txtBudget=$_POST["txtBudget"]
$txtUsed=$_POST["txtUsed"]
echo "$txtCustomerID,$txtName,$txtEmail,$txtCountryCode,$txtBudget,$txtUsed";
//--------------------------------
$objConnect = mysql_connect("localhost","sa","***") or die("Error Connect to Database");
$objDB = mysql_select_db("hr_Employee");
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."' ";
$strSQL .=",'".$_POST["txtCountryCode"]."','".$_POST["txtBudget"]."','".$_POST["txtUsed"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
ถ้ามีค่ามา ก็ต้องเช็คในส่วนของ sql ที่ insert ครับ
หรือลองแบบนี้ครับ
Code (PHP)
$txtCustomerID=$_POST["txtCustomerID"];
$txtName=$_POST["txtName"]
$txtEmail=$_POST["txtEmail"]
$txtCountryCode=$_POST["txtCountryCode"]
$txtBudget=$_POST["txtBudget"]
$txtUsed=$_POST["txtUsed"]
echo "$txtCustomerID,$txtName,$txtEmail,$txtCountryCode,$txtBudget,$txtUsed";
$objConnect = mysql_connect("localhost","sa","***") or die("Error Connect to Database");
$objDB = mysql_select_db("hr_Employee");
$strSQL = "INSERT INTO customer(CustomerID,Name,Email,CountryCode,Budget,Used)
VALUES('$txtCustomerID','$txtName','$txtEmail','$txtCountryCode','$txtBudget','$txtUsed') ";
|
ประวัติการแก้ไข 2011-03-09 11:35:50 2011-03-09 11:36:42 2011-03-09 11:38:09
 |
 |
 |
 |
Date :
2011-03-09 11:32:44 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะคะคุณ tong
แต่มันไม่มีค่าอยุ่ใน sql server เลยอ่ะคะ
เหมือนข้อมุลมันมันไม่ส่งไปอ่ะคะ
|
 |
 |
 |
 |
Date :
2011-03-09 13:05:24 |
By :
อยากรู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>test</title>
</head>
<body>
<form action="AddSave.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID" size="5"></div></td>
<td><input type="text" name="txtName" size="20"></td>
<td><input type="text" name="txtEmail" size="20"></td>
<td><div align="center"><input type="text" name="txtCountryCode" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget" size="5"></td>
<td align="right"><input type="text" name="txtUsed" size="5"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Code (PHP)
<html>
<head>
<title>test</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","sa","***") or die("Error Connect to Database");
$objDB = mysql_select_db("hr_Employee");
$strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) VALUES ('$_POST[txtCustomerID]','$_POST[txtName]','$_POST[txtEmail]','$_POST[txtCountryCode]','$_POST[txtBudget]','$_POST[txtUsed]')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
txtCustomerID ในฐานข้อมูลเก็บเป็นอะไร INT (Autoincrement) หรือป่าว
|
 |
 |
 |
 |
Date :
2011-03-09 13:07:57 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo $strSQL;
แล้วเอาคำสั่งไปรันใน mysql ดูครับ ว่ามัน insert ข้อมูลลงได้หรือป่าว
|
 |
 |
 |
 |
Date :
2011-03-09 13:10:16 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่คะเป็น int
พอรันแล้วมันไม่ขึ้นอะไรเลยคะ
โค้ดก็ไม่ผิดใช่ไหมคะ หรือจะผิดที่ database หรือเปล่าคะ
|
 |
 |
 |
 |
Date :
2011-03-09 13:13:30 |
By :
อยากรู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนแล้วคะ ตอนแรกก็คือว่าเป็นตรง function mssql เพราะใช้ฐานข้อมูล sql server
แต่พอรันแล้วใส่ข้อมูลได้หมด พอกดตกลงก็กลายเป็นหน้าว่างเปล่า
พอไปดู table customer ที่เราใส่ข้อมูลลงไป ใน sql server ก้ไม่ขึ้นข้อมุลไรเลย
|
 |
 |
 |
 |
Date :
2011-03-09 13:48:16 |
By :
อยากรู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้ยังครับ
|
 |
 |
 |
 |
Date :
2011-03-09 13:54:38 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังเลยคะก็ไม่รู้ว่าเป็นไร แค่ก๊อบโค้ดจาก thaicreate ไปและก้เปลี่ยนแค่ตรง ชื่อ ("localhost","sa","***") เป็นของเรา
และก้ลองไปสร้าง table customer ใน sql server ของเราก็ไม่ได้เหมือนเดิม
งง มากเลยคะ เหมือนจะง่ายแต่ทำไมแค่นี้ก็ทำไม่ได้ เฮ้อ..เซ็งอย่างแรงส์
|
 |
 |
 |
 |
Date :
2011-03-09 14:15:47 |
By :
อ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษทีครับ sql server ผมก็ไม่เคยลองด้วยอะครับ
|
 |
 |
 |
 |
Date :
2011-03-09 14:23:59 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
grant สิทธิ์ user sa หรือยังครับ แล้วพาสเวิร์ดตั้งเป็น *** หรอ
|
 |
 |
 |
 |
Date :
2011-03-09 14:33:35 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
grant สิทธิ์ user sa นี่คืออะไรคะ กำหนดสิทธิในการเข้าถึงให้กับ user หรือว่าไงคะ
ส่วน pass ไม่ใช่*** คะ แต่ก๊อบ file ลงเลยพิมพ์ *** เฉยๆ คะ
|
 |
 |
 |
 |
Date :
2011-03-09 15:19:58 |
By :
อยากรู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|