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,028

HOME > PHP > PHP Forum > ถามพี่ๆ เรื่องการอัพเดท 2 ตาราง เมื่อ get ค่ามาจากอีกหน้านึงค่ะ



 

ถามพี่ๆ เรื่องการอัพเดท 2 ตาราง เมื่อ get ค่ามาจากอีกหน้านึงค่ะ

 



Topic : 076852

Guest




คือจาก updatedata_admin.php แล้วส่งค่าไปยัง updatedata.php โดยผ่าน $_GET เมื่อ update และกด submit แล้ว ก็ขึ้นข้อความนี้ค่ะ "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where ProductID='8850718806195'' at line 1" คือหนูเขียน sql ผิด หรือว่า ยังไงคะ ช่วยดูให้หน่อยนะคะ ขอบคุณค่ะ ^^
อันนี้ updatedata_admin.php ค่ะ
Code (PHP)
 
<?
ob_start();
session_start();
if($_SESSION["adminlogin"]=="")
{
header('location:login.php');
exit();
} ; ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Update product's data</title>
<style type="text/css">
<!--
.style2 {font-size: 18px; font-weight: bold; }
-->
</style>
</head>
<body>
 <? 
	require ("config.php");
	require ("function.php"); 
		if($_GET["Action"]=="Delete")
				{
					$sql_del= "delete from nutritionfact where ProductID='".$_GET["ProductID"]."' and Nutrient='".$_GET["Nutrient"]."'";
					$dbquery_del = mysql_query($sql_del) or die(mysql_error());
					echo"<script language='JavaScript'>";
					echo"alert('ลบข้อมูลเรียบร้อยแล้ว');";
					echo"window.location='updatedata_admin.php';";
					echo"</script>";	 		}		
				

 include "head.php"; ?>
	
	<table width=1366>
		<tr><td width=266 bgcolor=#F0FFF0 valign=top>
	<ul>
    	<li><a href=adddata_admin.php><h3>Add product's data</h3></a></li>
		<li><a href=updatedata_admin.php><h3>Edit-Delete product's data</h3></a></li>
		<li><a href=addnutrient_admin.php><h3>Add product's nutrient</h3></a></li>
    	<li><a href=adddate_admin.php><h3>Add product's date</h3></a></li>
		<li><a href=delete_admin.php><h3>Delete product's date</h3></a></li>
		<li><a href=addstandard_admin.php><h3>Add standard</h3></a></li>
		<li><a href=updatestandard_admin.php><h3>Edit-Delete standard</h3></a></li>
		<li><a href=addcom_admin.php><h3>Add computer</h3></a></li>
		<li><a href=updatecom_admin.php><h3>Edit-Delete computer</h3></a></li>
		<li><a href=homepage.php><h3>Homepage</h3></a></li>
 		<li><a href=logout.php><h3>Log out</h3></a></li>
    	</ul> 
	</td>
	<td width=1200 bgcolor=#C1FFC1>
	
		<table border="1" width="100%">
		<tr><td><div align="center" class="style2">Product's ID</div></td>
		<td><div align="center" class="style2">Picture</div></td>
		<td><div align="center" class="style2">Product's Name</div></td>
		<td><div align="center" class="style2">Size</div></td>
		<td><div align="center" class="style2">Times</div></td>
		<td><div align="center" class="style2">Nutrient</div></td>
		<td><div align="center" class="style2">Volume</div></td>
		<td><div align="center" class="style2">Unit</div></td>
		<td><div align="center" class="style2">Type</div></td>
		<td><div align="center" class="style2">ProductType</div></td>
		<td><div align="center" class="style2">Edit</div></td>
		<td><div align="center" class="style2">Delete</div></td>
		</tr>
		  <?
			$sql_data = "select product.ProductID, product.ProductName, product.Size, product.Times, product.Type, product.ProductType, product.Pic, nutritionfact.ProductID, nutritionfact.Nutrient, nutritionfact.Volume, nutritionfact.Unit from product,nutritionfact where nutritionfact.ProductID=product.ProductID";
			$dbquery_data = mysql_query($sql_data) or die (mysql_error());
			$num_rows_data = mysql_num_rows($dbquery_data);
			while ($result = mysql_fetch_array($dbquery_data))
			{
		$ProductID = $result["ProductID"];
		$productname = $result["ProductName"];
		$serving = $result["Size"];
		$times = $result["Times"];
		$nutrient = $result["Nutrient"];
		$Pic = $result["Pic"];
		$volume = $result["Volume"];
		$unit = $result["Unit"];
		$type = $result["Type"];
		$producttype = $result["ProductType"]; 
		echo "<tr align='center'>";
		echo "<td>$ProductID</td><td><img src='$Pic' height='100'></td><td>$productname</td><td>$serving</td><td>$times ครั้ง</td><td>$nutrient</td><td>$volume</td><td>$unit</td><td>";
		switch($type) { 
  		case "0": echo "-"; 
				  break;
		case "1": echo "เด็กและทารกไม่ควรรับประทาน รับประทานวันละไม่เกิน 1 ลิตร";
				  break;	
		case "2": echo "ใช้สำหรับผู้ใหญ่เท่านั้น ในการควบคุมน้ำหนักและควบคุมระดับน้ำตาลในเลือด"; 
				  break;
		case "3": echo "เพื่อคุณค่าทางโภชนาการควรเติมเนื้อสัตว์ ผัก ไข่ ตามต้องการ"; 
				  break;
		case "4": echo "เครื่องดื่มนี้มีส่วนผสมของคาเฟอีน";
				  break;
		case "5": echo "ใช้ตามคำแนะนำของแพทย์";
				  break; 
		case "6": echo "เด็กไม่ควรรับประทาน"; 
				  break;
		case "7": echo "เด็กควรบริโภคแต่น้อย";
				  break; }
				  echo "</td><td>";
		switch($producttype){
		case "1": echo "อาหารมื้อหลัก";
				  break;
		case "2": echo "อาหารระหว่างมื้อ";
				  break;}
		echo "</td>"; ?>
		<script language="javascript">
		function Conf<?=$result["ProductID"]; ?>(object) {
if (confirm("ยืนยันการลบ [  <?=$result["ProductName"]; ?> ] ") ==true) {
return true;
}
return false;
}
</script>		
		<td><div align="center"><a href="updatedata.php?ProductID=<?=$result["ProductID"];?>&Nutrient=<?=$result["Nutrient"];?>"><img src="../nutriproject/sign/edit.png" height="20" border="0"></a></div></td>
        <td width="133"><div align="center"><a href="<?=$_SERVER['PHP_SELF'];?>?Action=Delete&ProductID=<?=$result["ProductID"];?>&Nutrient=<?=$result["Nutrient"];?>&file1=<?=$result["PictureSmall"];?>&file2=<?=$result["PictureBig"];?>" onClick="return Conf<?=$result["ProductID"]; ?>(this)"><img src="../nutriproject/sign/delete.png" height="20" border="0"></a></div></td>
      </tr>
      <?
	                         	}
	                      	?>
	</table></table>
</body>
</html>

อันนี้ updatedata.php ค่ะ
Code (PHP)
<?
ob_start();
session_start();
if($_SESSION["adminlogin"]=="")
{
header('location:login.php');
exit();
} 
require ("config.php");
require ("function.php");

//=========== กรณีมีการแก้ไขรายการสินค้า
 		if($_GET["Action"]=="Save")
	    {
			$sql_up = "update product set ProductID='$_POST[txtpid]',ProductName='$_POST[txtprod]', Size='$_POST[txtsize]', Times='$_POST[txttime]', Type='$_POST[chktype]', ProductType='$_POST[chkptype]', where ProductID='$_GET[ProductID]'";
            $dbquery_up = mysql_query($sql_up) or die(mysql_error());
		
			if($_FILES["fileupload"]["name"] != "")
			{
				if(move_uploaded_file($_FILES["fileupload"]["tmp_name"],"image/".$_FILES["fileupload"]["name"]))
				{
					// Delete Old File        
						@unlink("image/".$_POST["fileupload"]);
					// update new file
					$sql_up = "update product ";
					$sql_up .=" set Pic='image/".$_FILES["fileupload"]["name"]."' where ProductID='$_GET[ProductID]'";
					$dbquery_up = mysql_query($sql_up) or die(mysql_error());
					echo "Copy/Upload complete<br>";
				}
			}
			$sql_up2 = "update lot set ProductID='$_POST[txtpid]', Nutrient='$_POST[txtnutr]', Volume='$_POST[txtvolu]', Unit='$_POST[txtunit]' where ProductID='$_GET[ProductID]' and Nutrient='$_GET[Nutrient]'"; 
			?>		
			<script language='JavaScript'>
			alert('แก้ไขข้อมูลเรียบร้อยแล้ว')
			window.location='update_admin.php'
			</script>		  
	<?	}
					  
?>
<html>
<title>Edit Product's Data</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<script language="JavaScript" src="editor.js"></script>
<script type="text/javascript">
function senddata()
{
	if(document.getElementById('txtpid').value.length == 0)
	{
		alert ('ระบุรหัสผลิตภัณฑ์ด้วยค่ะ');
		return false;
	}
	document.getElementById('submit').disabled = true;
	return true;
}
function AddOk(pathfile)
{
	document.getElementById('fileupload').value = "";
	document.getElementById('showdetail').innerHTML = 'เพิ่มข้อมูลเสร็จเรียบร้อยแล้ว';
	document.getElementById('submit').disabled = false;
	document.getElementById('AddPForm').reset();
	return true;
}
</script>
<div align="center"><br>
<?
//===========  อ่านว่าคือสินค้าชนิดใด
$result1=select("product","where 1=1 and ProductID='".$_GET["ProductID"]."'");
$result2=select("nutritionfact","where ProductID='".$_GET["ProductID"]."' and Nutrient='".$_GET["Nutrient"]."'");
if(!$result1 && !$result2)
{
header("location:update_admin.php");
}

?>
 <form name="frm<?=$i;?>" id="AddPForm" method="post" action="<?=$_SERVER['PHP_SELF'];?>?ProductID=<?=$_GET["ProductID"];?>&Nutrient=<?=$_GET["Nutrient"];?>&Action=Save" enctype="multipart/form-data" onSubmit="return checkvalue()">
  <table cellspacing=1 cellpadding=3 width="56%" bgcolor=#CCCCCC border=0 align="center" height="10">
    <tbody>
      <tr bgcolor=#e5e5e5> 
        <td  bgcolor="#FFFFFF"> <script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script> 
<script language="JavaScript">
function checkvalue()
{


}
</script>
          <table width="100%" border="0" cellspacing="2" cellpadding="2">
            <tr> 
              <td width="25%">&nbsp;</td>
              <td width="75%">&nbsp;</td>
            </tr>
            <tr> 
              <td valign="top"><font size="+1">Product's ID</font></td>
              <td><input name="txtpid" type="text" class="txtbox" id="txtpid" value="<?=$result1["ProductID"];?>" maxlength="20" readonly="true"> 
              </td>
            </tr>
            <tr> 
              <td valign="top"><font size="+1">Product's Name</font></td>
              <td><input name="txtprod" type="text" class="txtbox" id="txtprod" value="<?=$result1["ProductName"];?>"  size="16" maxlength="20">
             </td>
            </tr>
            <tr> 
              <td valign="top"><font size="+1">Size</font></td>
              <td><input name="txtsize" type="text" class="txtbox" id="txtsize" value="<?=$result1["Size"];?>" size="16" maxlength="20"></td>
            </tr>
            <tr> 
              <td valign="top"><font size="+1">Times</font></td>
              <td><input name="txttime" type="text" class="txtbox" id="txttime" value="<?=$result1["Times"];?>" size="16" maxlength="20">
                ครั้ง </td>
            </tr>
            <tr> 
              <td valign="top"><font size="+1">Nutrient</font></td>
              <td><input name="txtnutr" type="text" class="txtbox" id="txtnutr" value="<?=$result2["Nutrient"];?>" size="16" maxlength="20"></td>
            </tr>
			<tr> 
              <td valign="top"><font size="+1">Volume</font></td>
              <td><input name="txtvolu" type="text" class="txtbox" id="txtvolu" value="<?=$result2["Volume"];?>" size="16" maxlength="20">  <input name="txtunit" type="text" class="txtbox" id="txtunit" value="<?=$result2["Unit"];?>" size="16" maxlength="20"></td>
            </tr>
			<tr> 
              <td valign="top"><font size="+1">Product Type</font></td>
              <td><input type="checkbox" name="chkptype" value="1" /> อาหารมื้อหลัก&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="chkptype" value="2" /> อาหารระหว่างมื้อ</td>
            </tr>
			<tr> 
              <td valign="top"><font size="+1">Type</font></td>
              <td><p>
                <input type="checkbox" name="chktype" value"1"  />
                เครื่องดื่มเกลือแร่&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="chktype" value="2"  /> 
                อาหารหรือเครื่องดื่มที่มีวัตถุให้ความหวานแทนน้ำตาล</p>
                <p>
                  <input type="checkbox" name="chktype" value="3"  />
                  บะหมี่กึ่งสำเร็จรูป 
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
                   <input type="checkbox" name="chktype" value="4"  />
                  เครื่องดื่มที่มีส่วนผสมของคาเฟอีน</p>
                <p>     
                  <input type="checkbox" name="chktype" value="5"  />
                  อาหารทางการแพทย์ 
                  &nbsp;&nbsp;&nbsp;
                  <input type="checkbox" name="chktype" value="6"  />
                  หมากฝรั่ง ลูกอมที่มีส่วนผสมของวัตถุให้ความหวานแทนน้ำตาล </p>
                <p>
                  <input type="checkbox" name="chktype" value="7"  /> 
		วุ้นสำเร็จรูป &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
         <input type="checkbox" name="chktype" value="0"  /> อื่นๆ</td>
			
            </tr>
			<tr> 
              <td valign="top"><font size="+1">รูปสินค้า</font></td>
              <td><input name="fileupload" type="file" class="txtbox" id="fileupload" value="<?=$result["Pic"];?>"></td>
			
            </tr>
            <tr> 
              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
              <td><input name="Submit" type="submit" class="button" value="Done"> 
                <input name="Cancel" type="button" class="button" id="Cancel" value="Cancle" onClick="window.location='update_admin.php';"></td>
            </tr>
            <tr> 
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr> 
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
          </table></td>
      </tr>
  
    </tbody>
  </table>
  </form>




Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-04-09 17:50:59 By : Supergirl View : 871 Reply : 2
 

 

No. 1



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



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


ผมคิดว่านะ

น่าจะผิดตรง sql update
Code (PHP)
$sql_up = "update product set ProductID='$_POST[txtpid]',ProductName='$_POST[txtprod]', Size='$_POST[txtsize]', Times='$_POST[txttime]', Type='$_POST[chktype]', ProductType='$_POST[chkptype]', where ProductID='$_GET[ProductID]'";
            $dbquery_up = mysql_query($sql_up) or die(mysql_error());



where ProductID = ตรงนี้น่าจะผิด เพราะ where เเล้วไม่เจอค่าตามที่ where เหตุผลเกิดจาก update product set ProductID ถูกอัพเดตไปเเล้วเลยหาไม่เจอ เลยเกิด error อัพเดตซ้ำซ้อน






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-09 18:38:02 By : 51035354
 


 

No. 2

Guest


อ่อ หนูเจอแล้วค่ะ
จากโค้ดที่พี่ JaาeUาe เอามาให้ดู หนูเจอเครื่องหมาย , ข้างหน้า where ค่ะ ฮ่าๆ
พอลบออก ก็อัพเดตได้แล้วค่ะ ขอบคุณนะคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-09 19:15:35 By : Supergirl
 

   

ค้นหาข้อมูล


   
 

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