bli maaf aku mau minta tolong lagi ni...aku pingin nyimpen file .swf ke mysql tapi cuma pathnya aja..aku udh coba bikin tapi koq datanya ga keinput ya..aku salah dimana ya? aku bikin pake php 5 yang di netbeans bli..ni yang udh aku cb bikin..
ni tabel materinya
CREATE TABLE `materi` (
  `id_materi` varchar(10) NOT NULL default '',
  `nama_materi` varchar(35) NOT NULL default '',
  `materi` varchar(40) NOT NULL,
  `id_kelas` varchar(10) NOT NULL,
  PRIMARY KEY  (`id_materi`),
  KEY `FK_materi` (`id_kelas`),
  CONSTRAINT `FK_materi` FOREIGN KEY (`id_kelas`) REFERENCES `kelas` (`id_kelas`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ni form uploadnya insert_materi.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Belajar Bahasa Mandarin - Data Siswa</title>
        <meta name="keywords" content="Business Website, free templates, website templates, 3-column layout, CSS, XHTML" />
        <meta name="description" content="Business Website, 3-column layout, free CSS template from templatemo.com" />
        <style type="text/css" title="currentStyle">
            @import "../media/css/demo_page.css";
            @import "../media/css/demo_table_jui.css";
            @import "../media/jquery-ui-1.8.4.custom.css";
        </style>
        <script type="text/javascript" language="javascript" src="../media/js/jquery.js"></script>

        <script type="text/javascript" language="javascript" src="../media/js/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                oTable = $('#datatables').dataTable({
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers"
                });
            } );
        </script>
        <link rel="stylesheet" type="text/css" href="../default.css" media="screen" />

    </head>



    <body>
        <div>
            <div class="top">
                <div class="header">
                    <div class="left">&nbsp;&nbsp;&nbsp;BELAJAR BAHASA MANDARIN </div>
                    <div class="right">
                        <div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container">
                <div class="navigation">
                    <a href="#" title="Home">HOME</a>
                    <a href="../admin/data_materi.php" title="Materi">Materi</a>
                    <a href="../admin/data_latihan.php" title="Latihan">Latihan</a>
                    <a href="../admin/data_siswa.php" title="Siswa">Siswa</a>
                    <div class="clearer">
                        <span></span>
                    </div>
                </div>
                <div class="main">
                    <div class="content">
                        <form name="tambahmateri" method="POST" entype="multipart/form-data"action="proses_tambahmateri.php" target="_self">
                            <table>
                                <tr>
                                    <td width="150">ID Materi</td>
                                    <td width="15">:</td>
                                    <td>
                                        <input type="text"name="id_materi"size="30" maxlength="15"/>*)
                                    </td>
                                </tr>
                                <tr>
                                    <td width="150">Nama Materi</td>
                                    <td width="15">:</td>
                                    <td>
                                        <input type="text"name="nama_materi"size="30"maxlength="100"/>*)
                                    </td>
                                </tr>
                                <tr>
                                    <td width="150">Materi</td>
                                    <td width="15">:</td>
                                    <td colspan="4">
                                        <input type="file" name="materi" size="30" maxlength="30"/>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Kelas</td>
                                    <td>:</td>
                                    <td>
                                        <select name="id_kelas">
                                            <option value='0'>- Pilih Nama Kelas -</option>
                                            <?php
                                            include '../konfigurasi/koneksi.php';
                                            $q = mysql_query("SELECT kelas FROM kelas ORDER BY kelas ASC;");

                                            while ($row1 = mysql_fetch_array($q)) {
                                                echo "<option value=$row1[id_kelas]>$row1[kelas]</option>";
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3"> *) isikan secara lengkap <br/>
                                    </td>
                                </tr>
                                <tr>
                                    <th colspan='6'>
                                        <input type="submit" name="Simpan" value="Simpan"/>
                                        <a href="insert_materi.php">
                                            <input type="button" value="Batal"/>
                                        </a>
                                    </th>
                                </tr>
                            </table>
                        </form>
                        <tr>
                            <td colspan="2" valign=top>
                                <table id = "datatables" class ="display" width="100%" border="0" cellspacing="0" cellpadding="5">
                                    <thead>
                                        <tr>
                                            <th>ID Materi</th>
                                            <th>Nama Materi</th>
                                            <th>Kelas</th>
                                            <th>Edit</th>
                                            <th>Hapus</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            include '../konfigurasi/koneksi.php';
                                            $view = mysql_query("SELECT kelas.kelas, materi.*
                                                    FROM bahasa_mandarin.materi
                                                    INNER JOIN bahasa_mandarin.kelas
                                                    ON (materi.id_kelas = kelas.id_kelas)
                                                    ORDER BY kelas.kelas ASC;");

                                            while ($row = mysql_fetch_array($view)) {
                                                echo"<tr><td>";
                                                echo $row['id_materi'];
                                                echo "</td><td>";
                                                echo $row['nama_materi'];
                                                echo "</td><td><center>";
                                                echo $row['kelas'];
                                                echo"</td><td>";
                                                echo "<a href=edit_materi.php?id_materi=$row[id_materi]>";
                                                echo"<img src='../gambar/edit.png' >";
                                                echo"</a>";
                                                echo "</td><td><center>";
                                                echo "<a href=\"../admin/proses_hapusmateri.php?id_materi=$row[id_materi]\" onclick=\"return confirm('Anda yakin akan mengapus data materi $row[nama_materi]?');\">";
                                                echo "<img src='../gambar/delete.gif'>";
                                                echo "</a>";
                                                echo "</td>";
                                            }
                                        ?>
                                    </tbody>
                                </table>
                            </td>
                        </tr>

                    </div>
                    <div class="sidenav">
                        <h2>FlexCMS</h2>
                        <ul>
                            <li><a href="#" title="Home">Home </a></li>
                            <li><a href="#" title="Downloads">Forest
                                    Green </a></li>
                            <li><a href="http://www.flexcms.co.uk/FlexCMS_Documentation.aspx" title="Documentation">Trees </a></li>
                            <li><a href="#" title="FAQs">About Us </a></li>
                            <li><a href="http://www.flexcms.co.uk/FlexCMS_ContactUs.aspx" title="Contact Us">Contact Us </a></li>
                        </ul>
                        <h2>Membership</h2>
                        <ul>
                            <li><a href="#">Login / Register</a></li>
                            <li><a href="#">Forgot password?</a></li>
                        </ul>
                        <h2>FlexCMS Bespoke versions </h2>
                        <ul>
                            <li><a href="http://www.giant-systems.co.uk/">FlexCMS
                                </a></li>
                            <li><a href="http://www.giant-systems.co.uk/Ecommerce.aspx">FlexEcommerce</a></li>
                            <li><a href="http://www.giant-systems.co.uk/casestudies.aspx">FlexCMS
                                    portal server </a></li>
                            <li><a href="http://www.giant-systems.co.uk/casestudies.aspx">FlexCMS
                                    Intranet </a></li>
                        </ul>
                        <br />
                        <br />
                    </div>
                    <div class="clearer"><span></span></div>
                </div>
                <div class="footer">© Ilana Fedelia - <a href ="http://www.usd.ac.id">Universitas Sanata Dharma Yogyakarta </a> 2012- Design by <a href="http://www.giant-systems.co.uk" title="Giant Systems Web design">Giant Systems Ltd</a>
                </div>
            </div>
        </div>
        <div style="font-size: 0.8em; text-align: center; margin-top: 1em; margin-bottom: 1em;">
            Design downloaded from <a href="http://www.freewebtemplates.com/">Free
                Templates</a> - your source for free web templates<br />
            Supported by <a href="http://www.hosting24.com/" target="_blank">Hosting24.com</a>
        </div>
    </body></html>

ni proses_tambahmateri.php
<?php

session_start();
include '../konfigurasi/koneksi.php';


if (empty($_POST[id_materi]) || empty($_POST[nama_materi])) {
    echo"<script language='javascript'>alert('Isikan semua form yang bertanda bintang (*)');
			  window.location = '../admin/insert_materi.php'</script>";
} elseif ($_POST[kelas] == '') {
    echo "<script language='javascript'>alert('Isikan semua form yang bertanda bintang (*)');
			  window.location = '../admin/insert_materi.php'</script>";
} else {
    $numRowsIdMateri = mysql_num_rows(mysql_query("SELECT id_materi FROM materi WHERE id_materi = '$_POST[id_materi]'"));
    if ($numRowsIdMateri > 0) {
        echo "<script language='javascript'>alert('ID materi sudah digunakan,masukkan id materi yang benar.');
					window.location = '../admin/insert_materi.php'</script>";
    } else {
        if ($_FILES['materi']['size'] > 0 && $_FILES['materi']['error'] == 00) {
            //membaca nama file
            $fileName = $_FILES['materi']['name'];
            //membaca size file
            $_fileSize = $_FILES['materi']['size'];
            //membaca nama file temporary
            $tempName = $_FILES['materi']['tmp_name'];
            //membuka atau membongkar file
            $fp = fopen($tempName, 'r');
            //membaca isi dari file, membaca kode binernya
            $file_content = fread($fp, filesize($tempName) or die("Error:cannot read file"));
            //menyimpan kode binernya ke variabel, ini yang akan disimpan di database
            $file_content = mysql_real_escape_string($file_content) or die("error: cannot read file");
            //menutup file
            fclose($fp);
            $query = "insert into materi (id_materi,nama_materi,materi,id_ujian)values('$_POST[id_materi]','$_POST[nama_materi],'$file_content',$_POST[id_kelas])";
            $re=mysql_query($query)or die("insert gagal");
            echo"<script language='javascript'>alert('Materi $_POST[nama_materi] untuk kelas = $_POST[kelas] berhasil ditambahkan/disimpan');
    window.location='../admin/data_materi.php'</script>";
        }
    }
}
?>

makasih banyak sebelumnya bli :)
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Jan 29, 2013 · 0 Suka · 0 Tidak Suka
kamu pelajari http://www.myphptutorials.com/tutorials/39/membuat-galeri-foto, prinsipnya sama, berlaku untuk semua file