form_data_hewan.php
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="index.php">back</a>
<form enctype="multipart/form-data" method="post" action="save_data_hewan.php">
<table width="551" border="1">
<tr>
<td width="91">kategori</td>
<td width="11">:</td>
<td width="427" colspan="4">
<select name="frm_kategori">
<option value="1">Sapiiiii</option>
<option value="2">Kambiiiing</option>
</select>
</td>
</tr>
<tr>
<td>nama</td>
<td>:</td>
<td colspan="4"><input type="text" name="frm_nama_hewan"/></td>
</tr>
<tr>
<td>foto</td>
<td>:</td>
<td>
<p>Foto 1 :
<input type="file" name="fupload[]" />
</p>
<p>Foto 2 :
<input type="file" name="fupload[]" />
</p>
<p>
Foto 3 :
<input type="file" name="fupload[]" />
</p>
<p>
Foto 4 :
<input type="file" name="fupload[]" />
</p></td>
</tr>
<tr>
<td>jenis kelamin </td>
<td>:</td>
<td colspan="4">
<select name="frm_jenis_kelamin">
<option>Penjantan</option>
<option>Betina</option>
</select>
</td>
</tr>
<tr>
<td>bobot</td>
<td>:</td>
<td colspan="4"><input type="text" name="frm_bobot"/> Kg</td>
</tr>
<tr>
<td>harga beli </td>
<td>:</td>
<td colspan="4">
<input type="text" name="frm_harga_beli" />
</td>
</tr>
<tr>
<td>harga jual </td>
<td>:</td>
<td colspan="4">
<input type="text" name="frm_harga_jual" />
</td>
</tr>
<tr>
<td>deskripsi</td>
<td>:</td>
<td colspan="4">
<textarea name="frm_deskripsi"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="4">
<input type="submit" name="Submit" value="SIMPAN" />
</td>
</tr>
</table>
</form>
</body>
</html>
save_data_hewan.php
<?php
session_start();
error_reporting(0);
require_once('inc-db.php');
//exit;
$lokasi_file= $_FILES['fupload']['tmp_name'];
$nama_file= $_FILES['fupload']['name'];
$ukuran_file= $_FILES['fupload']['size'];
//-------------------------------------------foto----
$var_kategori=$_POST['frm_kategori'];
$var_nama_hewan=$_POST['frm_nama_hewan'];
$var_jenis_kelamin=$_POST['frm_jenis_kelamin'];
$var_bobot=$_POST['frm_bobot'];
$var_harga_beli=$_POST['frm_harga_beli'];
$var_harga_jual=$_POST['frm_harga_jual'];
$var_deskripsi=$_POST['frm_deskripsi'];
$date=date("Y-m-d, H:i");
foreach($nama_file as $index =>$foto_name){
if($index==1){
$foto_name."<br>";
$_SESSION['foto_name']=$foto_name;
}
}
/*echo "<b>foto : </b>".$_SESSION['foto_name']."<br><b>nama : </b> ".$var_nama."<br><b>kategori : </b> ".$var_kategori."<br> <b>jenis kelamin : </b>
".$var_jenis_kelamin."<br><b>bobot : </b>".$var_bobot."<br><b>harga beli : </b>".$var_harga_beli.
"<br><b>harga jual : </b>".$var_harga_jual."<br><b>var deskripsi : </b>".$var_deskripsi."<br>"; */
//echo "<br>file-file yang berhasil diupload <br>";
//exit;
//hitung jumlah file yang diuploud
$sql_Insert="INSERT INTO tb_hewan VALUES ('','".$_SESSION['foto_name']."','$var_nama_hewan','$var_jenis_kelamin','$var_bobot','$var_harga_beli',
'$var_harga_jual','$var_deskripsi','$date','$var_kategori')";
//echo $sql_Insert;
//exit;
$result=mysql_query($sql_Insert);
$hewan_id=mysql_insert_id();
$jml_file=count($nama_file);
$i=0;
//lakukan perulangan selama $i < julah file yang diupload
while($i < $jml_file){
if($nama_file !=""){
$derektori="foto/".$nama_file[$i];
move_uploaded_file($lokasi_file[$i],"$derektori");
// echo "Nama file <b>".$nama_file[$i]."</b><br>";
$sql_insert="INSERT INTO tb_foto VALUES ('','$nama_file[$i]','$hewan_id')";
$result=mysql_query($sql_insert);
}
$i++;
}
echo "berhasil";
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<a href="index.php">back</a>
<form enctype="multipart/form-data" method="post" action="save_data_hewan.php">
<table width="551" border="1">
<tr>
<td width="91">kategori</td>
<td width="11">:</td>
<td width="427" colspan="4">
<select name="frm_kategori">
<option value="1">Sapiiiii</option>
<option value="2">Kambiiiing</option>
</select>
</td>
</tr>
<tr>
<td>nama</td>
<td>:</td>
<td colspan="4"><input type="text" name="frm_nama_hewan"/></td>
</tr>
<tr>
<td>foto</td>
<td>:</td>
<td>
<p>Foto 1 :
<input type="file" name="fupload[]" />
</p>
<p>Foto 2 :
<input type="file" name="fupload[]" />
</p>
<p>
Foto 3 :
<input type="file" name="fupload[]" />
</p>
<p>
Foto 4 :
<input type="file" name="fupload[]" />
</p></td>
</tr>
<tr>
<td>jenis kelamin </td>
<td>:</td>
<td colspan="4">
<select name="frm_jenis_kelamin">
<option>Penjantan</option>
<option>Betina</option>
</select>
</td>
</tr>
<tr>
<td>bobot</td>
<td>:</td>
<td colspan="4"><input type="text" name="frm_bobot"/> Kg</td>
</tr>
<tr>
<td>harga beli </td>
<td>:</td>
<td colspan="4">
<input type="text" name="frm_harga_beli" />
</td>
</tr>
<tr>
<td>harga jual </td>
<td>:</td>
<td colspan="4">
<input type="text" name="frm_harga_jual" />
</td>
</tr>
<tr>
<td>deskripsi</td>
<td>:</td>
<td colspan="4">
<textarea name="frm_deskripsi"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="4">
<input type="submit" name="Submit" value="SIMPAN" />
</td>
</tr>
</table>
</form>
</body>
</html>
save_data_hewan.php
<?php
session_start();
error_reporting(0);
require_once('inc-db.php');
//exit;
$lokasi_file= $_FILES['fupload']['tmp_name'];
$nama_file= $_FILES['fupload']['name'];
$ukuran_file= $_FILES['fupload']['size'];
//-------------------------------------------foto----
$var_kategori=$_POST['frm_kategori'];
$var_nama_hewan=$_POST['frm_nama_hewan'];
$var_jenis_kelamin=$_POST['frm_jenis_kelamin'];
$var_bobot=$_POST['frm_bobot'];
$var_harga_beli=$_POST['frm_harga_beli'];
$var_harga_jual=$_POST['frm_harga_jual'];
$var_deskripsi=$_POST['frm_deskripsi'];
$date=date("Y-m-d, H:i");
foreach($nama_file as $index =>$foto_name){
if($index==1){
$foto_name."<br>";
$_SESSION['foto_name']=$foto_name;
}
}
/*echo "<b>foto : </b>".$_SESSION['foto_name']."<br><b>nama : </b> ".$var_nama."<br><b>kategori : </b> ".$var_kategori."<br> <b>jenis kelamin : </b>
".$var_jenis_kelamin."<br><b>bobot : </b>".$var_bobot."<br><b>harga beli : </b>".$var_harga_beli.
"<br><b>harga jual : </b>".$var_harga_jual."<br><b>var deskripsi : </b>".$var_deskripsi."<br>"; */
//echo "<br>file-file yang berhasil diupload <br>";
//exit;
//hitung jumlah file yang diuploud
$sql_Insert="INSERT INTO tb_hewan VALUES ('','".$_SESSION['foto_name']."','$var_nama_hewan','$var_jenis_kelamin','$var_bobot','$var_harga_beli',
'$var_harga_jual','$var_deskripsi','$date','$var_kategori')";
//echo $sql_Insert;
//exit;
$result=mysql_query($sql_Insert);
$hewan_id=mysql_insert_id();
$jml_file=count($nama_file);
$i=0;
//lakukan perulangan selama $i < julah file yang diupload
while($i < $jml_file){
if($nama_file !=""){
$derektori="foto/".$nama_file[$i];
move_uploaded_file($lokasi_file[$i],"$derektori");
// echo "Nama file <b>".$nama_file[$i]."</b><br>";
$sql_insert="INSERT INTO tb_foto VALUES ('','$nama_file[$i]','$hewan_id')";
$result=mysql_query($sql_insert);
}
$i++;
}
echo "berhasil";
?>
0 Response to "Upoud Multiple dengan PHP dan MySql"
Posting Komentar