lady_rysher 0 Report post Posted April 27, 2008 salam to allsy ade prob ckit utk coding multiple update nih.....boleh x sesaper yg xpert tolong tenggok kn kt mane yg salah...asyik x boleh update je.....ni coding utk form update dia<form id="form1" name="form1" method="post" action="proses_kemaskini.php"> <table width="50%" border="0" cellspacing="2" cellpadding="2"> <tr> <? while($row=mysql_fetch_array($result)) { ?> <td>Kod Barang </td> <td><input name="id[]" type="text" id="id[]" value="<?=$row['id'];?>" disabled/></td> </tr> <tr> <td>Butiran</td> <td>Kuantiti</td> </tr> <tr> <td><input name="butiran1[]" type="text" id="butiran1[]" value="<?=$row['barang'];?>" /></td> <td><input name="kuantiti1[]" type="text" id="kuantiti1[]" value="<?=$row['kuantiti'];?>" /></td> </tr> <? } ?> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> yang ni lak tuk proses dia <?php // connect to the database and select the correct database mysql_connect('localhost','root',''); mysql_select_db("course") or die("Unable to select database"); $size = count($_POST['butiran1']); for ($i = 0; $i < $size; $i++) { $sql = "UPDATE barang2 set barang = '".$_POST['butiran1'.$i]."', kuantiti = '".$_POST['kuantiti1'.$i]."' where id = '".$_POST['id'.$i]."'"; mysql_query($sql) or die ("Error in query: $sql"); } if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($result == FALSE) echo "data gagal dikemaskini"; mysql_close(); ?>hope korang sume dapat membantu....plzzzz...dh blur sesangat dh nih.... Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted April 30, 2008 ini yg awak buat<?php // connect to the database and select the correct database mysql_connect('localhost','root',''); mysql_select_db("course") or die("Unable to select database"); $size = count($_POST['butiran1']); for ($i = 0; $i < $size; $i++) { $sql = "UPDATE barang2 set barang = '".$_POST['butiran1'.$i]."', kuantiti = '".$_POST['kuantiti1'.$i]."' where id = '".$_POST['id'.$i]."'"; mysql_query($sql) or die ("Error in query: $sql"); } if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($result == FALSE) echo "data gagal dikemaskini"; mysql_close(); ?> sepatutnya macam ni <?php // connect to the database and select the correct database mysql_connect('localhost','root',''); mysql_select_db("course") or die("Unable to select database"); $size = count($_POST['butiran1']); for ($i = 0; $i < $size; $i++) { $sql = "UPDATE barang2 set barang = '".$_POST['butiran1'][$i]."', kuantiti = '".$_POST['kuantiti1'][$i]."' where id = '".$_POST['id'][$i]."'"; mysql_query($sql) or die ("Error in query: $sql"); } if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($result == FALSE) echo "data gagal dikemaskini"; mysql_close(); ?>memandangkan awak buat macam ni<input name="butiran1[]" type=text" id="butiran1[]" value="<?=$row['barang];?>" /> Quote Share this post Link to post Share on other sites
lady_rysher 0 Report post Posted May 2, 2008 still xboleh jalan lagi...x tahu nape....still cakap data gagal dikemaskini Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted May 2, 2008 still xboleh jalan lagi...x tahu nape....still cakap data gagal dikemaskiniboleh bagi db awak tak, dalam bentuk *.sqltable terpilih aje, bukan semua tablesekali data contoh Quote Share this post Link to post Share on other sites
lady_rysher 0 Report post Posted May 2, 2008 mmm...ni contoh table dia...tp data dalam table just dummy je la...just untuk testing query ni je-- phpMyAdmin SQL Dump -- version 2.11.4 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: May 02, 2008 at 10:20 AM -- Server version: 5.0.51 -- PHP Version: 5.2.5 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `course` -- -- -------------------------------------------------------- -- -- Table structure for table `barang2` -- CREATE TABLE IF NOT EXISTS `barang2` ( `id` varchar(7) NOT NULL, `barang` varchar(30) NOT NULL, `kuantiti` varchar(30) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `barang2` -- INSERT INTO `barang2` (`id`, `barang`, `kuantiti`) VALUES ('0002900', 'pensel', '3'), ('0002900', 'pembaris', '2'), ('0002900', 'pemadam', '1'), ('0003000', 'buku latihan', '10'), ('0003000', 'buku Computer Security', '1'); Quote Share this post Link to post Share on other sites
cyberfly 1 Report post Posted May 2, 2008 try tgk yg ni..maybe dapat membantu http://www.phpsimple.net/tutorials/update_mutiple_records/ Quote Share this post Link to post Share on other sites
li9ht 0 Report post Posted May 3, 2008 (edited) ur database is wrong.. where is ur primary key.. primary key shouldnt be redundant... redundant primary key will cause problem when try to modify the data... modify ur table and create a new primary key.. or just modify the id to make it a primary key.. when posting data.. the textfield shouldnt be disabled.. data wont be sent if the textfield is disabled..change the db to urs..<? mysql_connect('localhost','root',''); mysql_select_db("test") or die("Unable to select database"); ?> <form id="form1" name="form1" method="post" action="proses_kemaskini.php"> <table width="50%" border="0" cellspacing="2" cellpadding="2"> <tr> <? $a="select * from barang2"; $result=mysql_query($a); while($row=mysql_fetch_array($result)) { ?> <td>Kod Barang </td> <td><input name="id[]" type="text" id="id[]" value="<?=$row['id'];?>" /></td> </tr> <tr> <td>Butiran</td> <td>Kuantiti</td> </tr> <tr> <td><input name="butiran1[]" type="text" id="butiran1[]" value="<?=$row['barang'];?>" /></td> <td><input name="kuantiti1[]" type="text" id="kuantiti1[]" value="<?=$row['kuantiti'];?>" /></td> </tr> <? } ?> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> <?php // connect to the database and select the correct database mysql_connect('localhost','root',''); mysql_select_db("test") or die("Unable to select database"); $size = count($_POST['butiran1']); for ($i = 0; $i < $size; $i++) { $sql = "UPDATE barang2 set barang = '".$_POST['butiran1'][$i]."', kuantiti = '".$_POST['kuantiti1'][$i]."' where id = '".$_POST['id'][$i]."'"; $result=mysql_query($sql) or die ("Error in query: $sql"); } if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($result == FALSE) echo "data gagal dikemaskini"; mysql_close(); ?>tiba2 plak hilang post yg tny tuh.. anyway nie reply akutak tau soalan nie untuk sapa if unt aku.. aku rasa ada declare $result tuh.. $result=mysql_query($sql) or die ("Error in query: $sql");guna for loop pasal tuan punya thread guna for.. Edited May 3, 2008 by li9ht Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted May 3, 2008 (edited) try tgk yg ni..maybe dapat membantu http://www.phpsimple.net/tutorials/update_mutiple_records/terdapat perbezaan kalau guna disabled dan juga readonlykod proses_kemaskini.php<?php // connect to the database and select the correct database mysql_connect('localhost','root','007'); mysql_select_db("s_course") or die("Unable to select database"); echo "<pre>";print_r($_POST); $size = count($_POST['butiran']); for ($i = 0; $i < $size; $i++) { echo $sql = "UPDATE barang2 set kuantiti = '".$_POST['kuantiti'][$i]."', barang = '".$_POST['butiran'][$i]."' ". "where id = '".$_POST['id'][$i]."' and barang = '".$_POST['butiran'][$i]."' \r"; } echo "</pre>"; ?> <td><input name="id[]" type="text" id="id[]" value="<?=$row['id'];?>" disabled/></td> output Jika guna disable Array ( [butiran] => Array ( [0] => pensel [1] => pembaris [2] => pemadam [3] => buku latihan [4] => buku Computer Security ) [kuantiti] => Array ( [0] => 3 [1] => 2 [2] => 5 [3] => 10 [4] => 1 ) [pilih] => disable [Submit] => Submit ) UPDATE barang2 set kuantiti = '3', barang = 'pensel' where id = '' and barang = 'pensel' UPDATE barang2 set kuantiti = '2', barang = 'pembaris' where id = '' and barang = 'pembaris' UPDATE barang2 set kuantiti = '5', barang = 'pemadam' where id = '' and barang = 'pemadam' UPDATE barang2 set kuantiti = '10', barang = 'buku latihan' where id = '' and barang = 'buku latihan' UPDATE barang2 set kuantiti = '1', barang = 'buku Computer Security' where id = '' and barang = 'buku Computer Security' <td><input name="id[]" type="text" id="id[]" value="<?=$row['id'];?>" readonly/></td> Jika guna readonly Array ( [id] => Array ( [0] => 0002900 [1] => 0002900 [2] => 0002900 [3] => 0003000 [4] => 0003000 ) [butiran] => Array ( [0] => pensel [1] => pembaris [2] => pemadam [3] => buku latihan [4] => buku Computer Security ) [kuantiti] => Array ( [0] => 3 [1] => 2 [2] => 5 [3] => 10 [4] => 1 ) [pilih] => readonly [Submit] => Submit ) UPDATE barang2 set kuantiti = '3', barang = 'pensel' where id = '0002900' and barang = 'pensel' UPDATE barang2 set kuantiti = '2', barang = 'pembaris' where id = '0002900' and barang = 'pembaris' UPDATE barang2 set kuantiti = '5', barang = 'pemadam' where id = '0002900' and barang = 'pemadam' UPDATE barang2 set kuantiti = '10', barang = 'buku latihan' where id = '0003000' and barang = 'buku latihan' UPDATE barang2 set kuantiti = '1', barang = 'buku Computer Security' where id = '0003000' and barang = 'buku Computer Security' Edited May 3, 2008 by amin007 Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted May 3, 2008 (edited) ur database is wrong.. where is ur primary key.. primary key shouldnt be redundant... redundant primary key will cause problem when try to modify the data... modify ur table and create a new primary key.. or just modify the id to make it a primary key.. when posting data.. the textfield shouldnt be disabled.. data wont be sent if the textfield is disabled..change the db to urs..tiba2 plak hilang post yg tny tuh.. anyway nie reply akumengomen (komen laa) pada jawapan li9htnilah kod php selepas puas mengodekecho "<pre>";//print_r($_POST).""; $size = count($_POST['butiran']); for ($i = 0; $i < $size; $i++) { $sql = "UPDATE barang2 set kuantiti = '".$_POST['kuantiti'][$i]."' ,barang = '".$_POST['butiran'][$i]."' where id = '".$_POST['id'][$i]."' and barang = '".$_POST['butiran'][$i]."' \r"; $result=mysql_query($sql); if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini(".$_POST['id'][$i].",".$_POST['butiran'][$i].")</a><br>"; elseif ($result == FALSE) echo "data gagal dikemaskini(".$_POST['id'][$i].",".$_POST['butiran1'][$i].")<br>"; } echo "</pre>"; tapi nampak macam buruk pulak buat macam ni kalau ikutkan, sepatutnya output $result keluar sekali tapi kalau ikut $size, dia akan ulang sebanyak tu juga lady_rysher, awak buat macam ni mysql_query($sql) or die ("Error in query: $sql"); } if ($result == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($result == FALSE) echo "data gagal dikemaskini";saya juga tertanya-tanya $result datang dari mana???lepas tu awak nak buat if else , hasilnya mesti false Edited May 3, 2008 by amin007 Quote Share this post Link to post Share on other sites
lady_rysher 0 Report post Posted May 3, 2008 to li9ht ur were right..i've change my db and added a new primary keythen...$result tuh sepatutnye $sql...hehehe...xperasan...pe pun thanks a bunch...ni coding yang sy dh edit dr hasil tunjuk ajar amin007 n li9ht...<?php // connect to the database and select the correct database mysql_connect('localhost','root',''); mysql_select_db("course") or die("Unable to select database"); echo $size = count($_POST['barang']); for ($i = 0; $i < $size; $i++) { echo $sql = "UPDATE barang2 SET barang = '".$_POST['barang'][$i]."', kuantiti = '".$_POST['kuantiti'][$i]."' where id = '".$_POST['id'][$i]."' AND no_pesanan = '".$_POST['no_pesanan'][$i]."'"; mysql_query($sql) or die ("Error in query: $sql"); } if ($sql == TRUE) echo "<a href='papar.php'>data berjaya dikemaskini</a> "; if ($sql == FALSE) echo "data gagal dikemaskini"; mysql_close(); ?>to amin007 tq bebanyak..... Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted May 4, 2008 to li9ht ur were right..i've change my db and added a new primary keythen...$result tuh sepatutnye $sql...hehehe...xperasan...pe pun thanks a bunch...ni coding yang sy dh edit dr hasil tunjuk ajar amin007 n li9ht...to amin007 tq bebanyak..... pasal primary key tu,sya rasa awak boleh buat dua medan sekali gus sebagai primary keycontohCREATE TABLE IF NOT EXISTS `barang2` ( `id` varchar(7) NOT NULL, `barang` varchar(30) NOT NULL, `kuantiti` varchar(30) NOT NULL, PRIMARY KEY (`id`,`barang`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote Share this post Link to post Share on other sites
lady_rysher 0 Report post Posted May 4, 2008 mmmm....ok...ok...trimas.....mmm...kalau nk tanye lg satu boleh x...tp ni mayb x berkaitan dengan dengan multiple insert nih....ade x sesaper yg tahu camne nk buat no rujukkan contoh macam ni PUO/JMSK/300-8/5(25)...yang boleh auto increment, bile setiap kali user issued out a new surat, nombor dia akan bertambah jd PUO/JMSK/300-8/5(26) and so on... Quote Share this post Link to post Share on other sites
amin007 1 Report post Posted May 4, 2008 mmmm....ok...ok...trimas.....mmm...kalau nk tanye lg satu boleh x...tp ni mayb x berkaitan dengan dengan multiple insert nih....ade x sesaper yg tahu camne nk buat no rujukkan contoh macam ni PUO/JMSK/300-8/5(25)...yang boleh auto increment, bile setiap kali user issued out a new surat, nombor dia akan bertambah jd PUO/JMSK/300-8/5(26) and so on...rujuk ->http://www.phpeasystep.com/phptu/5.htmlfor ($n=1; $n <= 30; $n++) { echo "PUO/JMSK/300-8/5("; printf("%02d", $n); echo ")<br>"; }tapi bagi saya nombor surat tu macam susah nak buatsaya cadangkan buat medan berasingandari apa yang saya tahu,kalau nombor dalam kurungan (25) tu dah sampai 100kena tukar fail baru, jilid juga kena tukar kanoleh itu ... Quote Share this post Link to post Share on other sites