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 > ขอสอบถามเรื่องการดึงข้อมูลจากตารางนึงมาบันทึกใส่ในอีกตารางนึงหน่อยค่ะ



 

ขอสอบถามเรื่องการดึงข้อมูลจากตารางนึงมาบันทึกใส่ในอีกตารางนึงหน่อยค่ะ

 



Topic : 101945



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



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



คือตอนนี้มีตาราง add_product

รูป

แล้วได้ทำการดึงข้อมูลจากตารางนี้มาทำเป็น Dropdown ค่ะ

โดยได้ทำการดึงมาใส่ในนี้ค่ะ(กรอบแดง)

รูป

และเมื่อกดปุ่มบันทึกข้อมูลก็จะถูกบันทึกไว้ในตารางนี้ค่ะ

รูป

โดยที่ให้ ยี่ห้อ เพิ่มไปในช่อง ctm_product แล้วก็ รุ่น ใส่ไปในช่อง ctm_model

Code (PHP)
<?php require_once('Connections/AddDataCustomers.php');
include("header.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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO data_customers (ctm_name, ctm_surname, ctm_product, ctm_tel, ctm_date, ctm_fix) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['ctm_name'], "text"),
                       GetSQLValueString($_POST['ctm_surname'], "text"),
                       GetSQLValueString($_POST['ctm_product'], "text"),
                       GetSQLValueString($_POST['ctm_tel'], "int"),
                       GetSQLValueString($_POST['ctm_date'], "date"),
                       GetSQLValueString($_POST['ctm_fix'], "text"));

  mysql_select_db($database_AddDataCustomers, $AddDataCustomers);
  $Result1 = mysql_query($insertSQL, $AddDataCustomers) or die(mysql_error());

  $insertGoTo = "data-table.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!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>Insert Data</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table border="0" align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td align="center"><p>เพิ่มข้อมูลใหม่</p></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">ชื่อ:</td>
      <td><input type="text" name="ctm_name" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">นามสกุล:</td>
      <td><input type="text" name="ctm_surname" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">ยี่ห้อมือถือ:</td>
      <td><select name="add_product" id="add_product">
<?php
	$q="select * from add_product ";
	$qr=mysql_query($q);
	while($rs=mysql_fetch_array($qr)){
?>
  <option value="<?=$rs['model']?>"><?=$rs['brand']?></option>
  
<?php } ?>	
</select></td>
<tr valign="baseline">
 <td nowrap="nowrap" align="right">รุ่น:</td>
      <td><select name="add_product" id="add_product">
<?php
	$q="select * from add_product ";
	$qr=mysql_query($q);
	while($rs=mysql_fetch_array($qr)){
?>
  <option value="<?=$rs['brand']?>"><?=$rs['model']?></option>
  
<?php } ?>	
</select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">เบอร์ติดต่อ:</td>
      <td><input type="text" name="ctm_tel" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">วันที่มาซ่อม(ป-ด-ว):</td>
      <td>
	
  <input type="text" name="ctm_date" value="<?php echo date('Y-m-d'); ?>" size="32" />  

      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">บริการที่เข้ารับ:</td>
      <td><select name="ctm_fix" id="ctm_fix">
<option value="case1">case1</option>
<option value="case2">case2</option>
<option value="case3">case3</option>
</select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><center><input type="submit" value="บันทึก" />
        <input type="reset" name="resend" id="resend" value="ล้างข้อมูลทั้งหมด" />
      </center></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>


รบกวนช่วยชี้แนะแนวทางด้วยค่า

ขอบคุณค่ะ^^



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-10-22 22:36:44 By : aorplus View : 754 Reply : 4
 

 

No. 1



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



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

ไมโค๊ดเยอะจัง copy เขามาใช่มะ คุ้นๆ เขียนแค่นี้ก้อพอครับ

Code (PHP)
<?

if ($_POST){

$ctm_name = $_POST[ctm_name];
$ctm_surname = $_POST[ctm_surname];
$add_product = $_POST[add_product];
$add_product2 = $_POST[add_product2];
$ctm_tel = $_POST[ctm_tel];
$ctm_date = $_POST[ctm_date];
$ctm_fix = $_POST[ctm_fix];
$ctm_tel = $_POST[ctm_tel];
}

else
{
require_once('Connections/AddDataCustomers.php');
$sql = mysql_query ("insert into data_customers (ctm_name,ctm_surname, ctm_product, ctm_model,ctm_tel, ctm_date, ctm_fix) values (0,'$ctm_name','$ctm_surname','$add_product','$add_product2','$ctm_tel','$ctm_date','$ctm_fixl','$ctm_tel ')") or die (mysql_error());
}

if ($sql){

echo "เพิ่มข้อมูลเรียบร้อย";
}
else {

echo "ไม่สามารถเพิ่มข้อมูลได้";
}

?>



*เปลี่ยน ตรง <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

เป็น <form action="<? echo $PHP_SELF ?>" method="post" name="form1" id="form1"> ด้วยนะครับ


ปล. script นี้ผมเขียนสดยังไม่ได้ลอง test








ประวัติการแก้ไข
2013-10-22 23:16:43
2013-10-22 23:18:29
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-22 23:13:03 By : topza1412
 


 

No. 2



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



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

ขอบคุณนะคะ


ประวัติการแก้ไข
2013-10-22 23:50:06
2013-10-23 01:07:40
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-22 23:22:26 By : aorplus
 

 

No. 3



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



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

แล้วผลเปนไงบ้างครับ insert เข้าไหมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-23 07:48:53 By : topza1412
 


 

No. 4



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



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

เข้าค่ะ แต่ใช้เป็น select เลือกตารางเอา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-23 12:08:56 By : aorplus
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอสอบถามเรื่องการดึงข้อมูลจากตารางนึงมาบันทึกใส่ในอีกตารางนึงหน่อยค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่