kantal_kintilAvatar border
TS
kantal_kintil
[ASK PHP ] EDIT(UPDATE) RECORD DATABASE TABEL LEBIH DARI 1 DALAM 1 FILE
gan ane mau buat from update database pake input file tapi berbeda table antar form input 1(tabel pucuk) dan form input 2 (tabel daun)
codingnya sih sudah ampir selesai tapi ada error nya yang ke ganti cuma form input yang ke-2
form input yang pertama malah keluar error massage
coding
PHP Code:
<?php
$host
="localhost";
$username="root";
$password="root";
$db_name="cbrteh";
$tbl_name="pucuk";
$tbl_name2="daun";
mysql_connect("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="POST" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">

<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Gejala1</strong></td>
<td align="center"><strong>Gejala2</strong></td>
<td align="center"><strong>value</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
$id[]=$rows['id'];
?>

<tr>
<td align="center">
<input name="id[]" type="hidden" id="id" value="<?php echo $rows['id']; ?>">
</td>
<td align="center">
<input name="gejala1[]" type="text" id="gejala1" value="<?php echo $rows['gejala1']; ?>">
</td>
<td align="center">
<input name="gejala2[]" type="text" id="gejala2" value="<?php echo $rows['gejala2']; ?>">
</td>
<td align="center">
<input name="value[]" type="text" id="value" value="<?php echo $rows['value']; ?>">
</td>
</tr>
<?php
}
?>

<tr>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
mysql_connect
("$host""$username""$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql2="SELECT * FROM $tbl_name2";
$result=mysql_query($sql2);

// Count table rows
$count=mysql_num_rows($result);
?>

<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="POST" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">

<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Gejala1</strong></td>
<td align="center"><strong>Gejala2</strong></td>
<td align="center"><strong>value</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
$ida[]=$rows['id'];
?>

<tr>
<td align="center">
<input name="ida[]" type="hidden" id="id" value="<?php echo $rows['id']; ?>">
</td>
<td align="center">
<input name="gejala1a[]" type="text" id="gejala1" value="<?php echo $rows['gejala1']; ?>">
</td>
<td align="center">
<input name="gejala2a[]" type="text" id="gejala2" value="<?php echo $rows['gejala2']; ?>">
</td>
<td align="center">
<input name="valuea[]" type="text" id="value" value="<?php echo $rows['value']; ?>">
</td>
</tr>
<?php
}
?>

<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>

<?php
          
if(isset($_POST['Submit']))
{
    for(
$i=0;$i<$count;$i++)
    {
        
$sql1=mysql_query("UPDATE `".$tbl_name."` SET gejala1='".magic($_REQUEST['gejala1'][$i])."', gejala2='".magic($_REQUEST['gejala2'][$i])."', value='".magic($_REQUEST['value'][$i])."'  WHERE id='".magic($_REQUEST['id'][$i])."' ");
mysql_query($sql1);
  

     }
  for(
$i=0;$i<$count;$i++)
    {
        
$sql2=mysql_query("UPDATE `".$tbl_name2."` SET gejala1='".magic($_REQUEST['gejala1a'][$i])."', gejala2='".magic($_REQUEST['gejala2a'][$i])."', value='".magic($_REQUEST['valuea'][$i])."'  WHERE id='".magic($_REQUEST['ida'][$i])."' ");
mysql_query($sql2);


     }
}


function 
magic($value)
{
   if( 
get_magic_quotes_gpc() )
       
$value stripslashes$value );
   if( 
function_exists"mysql_real_escape_string" ) )
       
$value mysql_real_escape_string$value );
   else
       
$value addslashes$value );
   return 
$value;
}

?>

kalo di jalannin

ada emoticon-Blue Guy Cendol (L)emoticon-Blue Guy Cendol (L)emoticon-Blue Guy Cendol (L)loh
0
1K
1
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan