Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ถามเรื่องการ Insert ข้อมูลลงฐานข้อมูลโดยผ่านฟอร์ม ใช้โปรแกรม Dreamweaver CS5.5 ค่ะ



 

ถามเรื่องการ Insert ข้อมูลลงฐานข้อมูลโดยผ่านฟอร์ม ใช้โปรแกรม Dreamweaver CS5.5 ค่ะ

 



Topic : 108942



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์




อันนี้คือโค้ดทั้งหมดที่เขียนลงไปค่ะซึ่งพอกดบันทึกข้อมูลก็จะขึ้น ERROR
Code (PHP)
<?php require_once('Connections/ConDB.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_ConDB, $ConDB);
$query_R1 = "SELECT * FROM divisions ORDER BY d_name ASC";
$R1 = mysql_query($query_R1, $ConDB) or die(mysql_error());
$row_R1 = mysql_fetch_assoc($R1);
$totalRows_R1 = mysql_num_rows($R1);

mysql_select_db($database_ConDB, $ConDB);
$query_R2 = "SELECT * FROM groups ORDER BY g_name ASC";
$R2 = mysql_query($query_R2, $ConDB) or die(mysql_error());
$row_R2 = mysql_fetch_assoc($R2);
$totalRows_R2 = mysql_num_rows($R2);
?>
<!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>

<?php 
$conn=mysql_connect("localhost","root","1234")or die("Error Connect to Database");
if($conn){
mysql_query("SET NAMES UTF8");
mysql_select_db("teohong");
echo "เชื่อมต่อฐานข้อมูลเรียบร้อยแล้ว";
} else
{
echo "ไม่สามารถเชื่อต่อฐานข้อมูลได้";	
}

if($_POST['seve'])
{
echo "<pre>";
print_r($_POST);
echo "<pre>";
$NO = $_POST['NO'];
$ComputerName = $_POST['ComputerName'];
$datetime = $_POST['datetime'];
$Name = $_POST['Name'];
$division = $_POST['division'];
$group = $_POST['group'];
$requests = $_POST['requests'];
$Asset = $_POST['Asset'];
$seriai = $_POST['seriai'];
$Endtime = $_POST['Endtime'];
$details = $_POST['details'];

$Sql_add = "insert into db_request set
			NO = 'NO', 
			ComputerName='$ComputerName' ,
			datetime='NOW();',
			Name='$Name',
			division='$division',
			group='$group',
			requests='$requests',
			Asset='$Asset',
			seriai='$seriai',
			Endtime='$Endtime',
			details='$details'";


mysql_query($sql_add) or die(mysql_error());
echo "เพิ่มข้อมููลสำเร็จแล้ว";

}

?>
<td height="504" align="center" valign="top"><form id="form8" name="form8" method="POST">
      <input type="image" name="imageField6" id="imageField6" src="Head.jpg" />
    </form>
  <table width="1060" height="36" border="1">
      <tr>
        <td width="206" align="center"><form id="form3" name="form3" method="post" action="P1.php">
          <input type="image" name="imageField" id="imageField" src="H1.png" />
        </form></td>
        <td width="206" align="center"><form id="form4" name="form4" method="post" action="P2.php">
          <input type="image" name="imageField2" id="imageField2" src="H2.png" />
        </form></td>
        <td width="206" align="center"><form id="form5" name="form5" method="post" action="P3.php">
          <input type="image" name="imageField3" id="imageField3" src="H3.png" />
        </form></td>
        <td width="206" align="center"><form id="form6" name="form6" method="post" action="P4.php">
          <input type="image" name="imageField4" id="imageField4" src="H4.png" />
        </form></td>
        <td width="202" align="center"><form id="form2" name="form7" method="post" action="P5.php">
          <input type="image" name="imageField5" id="imageField5" src="H5.png" />
        </form></td>
      </tr>
  </table>
  <p>&nbsp;</p>
      <table width="1103" border="0">
        <tr>
          <td align="center"><form action="" method="POST" name="form1" id="form1">
            <table width="743" border="0">
              <tr>
                <td colspan="2" align="center"><strong>แจ้งขออุปกรณ์เพิ่ม</strong></td>
              </tr>
              <tr>
                <td width="296" align="right"><strong>Computer Name</strong></td>
                <td width="437"><input type="text" name="ComputerName" id="ComputerName" /></td>
              </tr>
              <tr>
                <td align="right"><strong>วัน/เวลา ที่แจ้ง</strong></td>
                <td><input name="dates" type="text" id="dates" value="<?=date('d/m/Y | h:i:s')?>"/></td>
              </tr>
              <tr>
                <td align="right"><strong>ชื่อผู้แจ้ง/นามสกุล(ไทย)</strong></td>
                <td><input type="text" name="Name" id="Name" /></td>
              </tr>
              <tr>
                <td align="right"><strong>แผนก</strong></td>
                <td><select name="divisions" id="divisions">
                  <option value="-">-กรุณาเลือก-</option>
                  <?php
do {  
?>
                  <option value="<?php echo $row_R1['d_name']?>"><?php echo $row_R1['d_name']?></option>
                  <?php
} while ($row_R1 = mysql_fetch_assoc($R1));
  $rows = mysql_num_rows($R1);
  if($rows > 0) {
      mysql_data_seek($R1, 0);
	  $row_R1 = mysql_fetch_assoc($R1);
  }
?>
                </select></td>
              </tr>
              <tr>
                <td align="right"><strong>กลุ่มธุรกิจ</strong></td>
                <td><select name="group" id="group">
                  <option value="-">-กรุณาเลือก-</option>
                  <?php
do {  
?>
                  <option value="<?php echo $row_R2['g_name']?>"><?php echo $row_R2['g_name']?></option>
                  <?php
} while ($row_R2 = mysql_fetch_assoc($R2));
  $rows = mysql_num_rows($R2);
  if($rows > 0) {
      mysql_data_seek($R2, 0);
	  $row_R2 = mysql_fetch_assoc($R2);
  }
?>
                </select></td>
              </tr>
              <tr>
                <td align="right"><strong>อุปกรณ์ที่ขอเพิ่ม</strong></td>
                <td><input type="text" name="request" id="request" /></td>
              </tr>
              <tr>
                <td align="right"><strong><strong>รายละเอียดของอุปกรณ์</strong>&nbsp;&nbsp; &nbsp;Asset NO</strong></td>
                <td><strong>
                  <input type="text" name="AssetNO" id="AssetNO" />
                </strong></td>
              </tr>
              <tr>
                <td align="right"><strong>&nbsp;Seriai NO. </strong></td>
                <td><strong>
                  <input type="text" name="SeriaiNO" id="SeriaiNO" />
                </strong></td>
              </tr>
              <tr>
                <td align="right"><strong>วันหมดอายุรับประกัน</strong></td>
                <td><input type="text" name="Endtime" id="Endtime" /></td>
              </tr>
              <tr>
                <td align="right" valign="top"><strong>รายละเอียดการดำเนินงาน</strong></td>
                <td><textarea name="detail" id="detail" cols="70" rows="7"></textarea></td>
              </tr>
            </table>
            <p>
              <input type="submit" name="seve" id="seve" value="บันทึก" />
              <input type="reset" name="Reset" id="Reset" value="Reset" />
            </p>
          </form></td>
        </tr>
    </table></td>
</body>
</html>
<?php
mysql_free_result($R1);

mysql_free_result($R2);
?>



อันนี้คือภาพERROR ที่แสดงออกมาอะค่ะ

11


อันนี้คือภาพฐานข้อมูลค่ะ

12

ช่วยทีนะคะ แก้มาหลายวันแล้ว เมื่อวานตั้งกระทู้ถามพอแก้ตามที่พี่ๆให้คำแนะนำก็ไม่ได้สักที



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-06-06 09:34:13 By : Loogsorn22 View : 1490 Reply : 7
 

 

No. 1



โพสกระทู้ ( 1,150 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

เขียนรวมไว้หน้าเดียวหมดเลย แปลกดี หุๆ

Code (PHP)
$Sql_add = "insert into db_request set
			NO = '$NO', 
			ComputerName='$ComputerName' ,
			datetime= NOW() ,
			Name='$Name',
			division='$division',
			group='$group',
			requests='$requests',
			Asset='$Asset',
			seriai='$seriai',
			Endtime='$Endtime',
			details='$details'";









ประวัติการแก้ไข
2014-06-06 10:07:28
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:06:30 By : progamer2000
 


 

No. 2



โพสกระทู้ ( 1,150 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (PHP)
<td><input type="text" name="request" id="request" /></td>

อย่างอันนี้ ไม่มี s แต่ตอนรับตัวแปร ที่ $requests = $_POST['requests'];

ดันรับแบบ มี s เจอหลายที่เลยครับ

ลองไล่ตัวแปร ใหม่นะครับ - -"



ประวัติการแก้ไข
2014-06-06 10:14:49
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:11:26 By : progamer2000
 

 

No. 3



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : progamer2000 เมื่อวันที่ 2014-06-06 10:11:26
รายละเอียดของการตอบ ::
แฮะๆ ค่ะๆ ถ้าไม่เขียนแบบไว้หน้าเดียวกันหมดต้องเขียนแบบไหนอะค่ะ พอดีศรก็ไม่ค่อยรู้เรื่องเท่าไหร่ พยายามนึกๆตามที่อาจารย์สอนมา555 ไม่รู้อะไรถูก อะไรผิด ขอคำแนะนำด้วยค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:15:38 By : Loogsorn22
 


 

No. 4



โพสกระทู้ ( 1,150 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

เขียนไปตามที่ถนัดก็ได้ครับ จะได้ไม่ งง

GetSQLValueString ฟังชั่นนี้ใช้งานด้วยหรือครับ ?

การ connect db ปรับมาใช้ รูปแบบ mysqli แบบ oop ดีกว่านะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:21:46 By : progamer2000
 


 

No. 5



โพสกระทู้ ( 46 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 4 เขียนโดย : progamer2000 เมื่อวันที่ 2014-06-06 10:21:46
รายละเอียดของการตอบ ::
ไม่เคยใช้ OOP เลยอะคะ ไม่รู้ว่าเขียนยังไง ตอนนี้มืดแปดด้านค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:28:44 By : Loogsorn22
 


 

No. 6



โพสกระทู้ ( 1,150 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

วิธีใช้ mysqli ดูกระทู้บนสุดเลยครับที่ปักหมุดอยู่


ประวัติการแก้ไข
2014-06-06 10:34:40
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 10:31:55 By : progamer2000
 


 

No. 7



โพสกระทู้ ( 1,666 )
บทความ ( 0 )



สถานะออฟไลน์


บรรทัด 084
NO = 'NO',



ซึ่งฟิลโนเป็น PK ไพรมารีตามกฏต้องไม่ซ้ำในรูปภาพDB ก็ขีดเส้นใต้ไว้ชัดเจนว่ามันคือไพรมารี่
ดังนั้นเมื่อเขียนแบบนี้ จะบันทึกได้แค่ตัวเดียว ถ้ามีตัวที่ 2 เข้ามา มันก็ไม่ได้สิครับ Error แน่นอน


วิธีแก้ใข
1. ไปปรับใน PhpMyadmin ให้ฟิล NO เป็น auto_increment
2. เอาบรรทัดที่บอกว่า NO = 'NO' ออกไป ไม่ต้องไประบุอะไรมัน เดี๋ยวมันรู้งานเอง




ประวัติการแก้ไข
2014-06-06 14:26:01
2014-06-06 14:29:09
2014-06-06 14:32:19
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-06 14:25:19 By : meannerss
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ถามเรื่องการ Insert ข้อมูลลงฐานข้อมูลโดยผ่านฟอร์ม ใช้โปรแกรม Dreamweaver CS5.5 ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่