input_berita_static.php

<?php

    include('../includes/koneksi.php');

    $id = isset($_POST['id']) ? $_POST['id'] : '';  
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';  
    $kategori = isset($_POST['kategori']) ? $_POST['kategori'] : ''; 
    $news = isset($_POST['news']) ? $_POST['news'] : '';
    $judul = isset($_POST['judul']) ? $_POST['judul'] : ''; 
    $page = isset($_POST['page']) ? $_POST['page'] : '';

    echo $id;

    //Load berita
    if (!empty($_GET['id'])){
        $result = mysql_query("SELECT * FROM static_page WHERE id =".$_GET['id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $id = $data['id'];
        $page = $data['page'];
        $judul = $data['judul'];
        $news = $data['isi_berita'];

        echo "variable";
        echo $id;
        echo $page;
        echo $judul;
        echo $news;
    }
    else
    {
    echo "unable to select static_page";
    }

    //Simpan berita 
    if (isset($_GET['ok'])){

        if (empty($_GET['id']))
            $sqlstr = "INSERT INTO static_page(page, judul, isi_berita) VALUES('".$page."','".$judul."','".$news."')";
        else
            $sqlstr = "UPDATE static_page SET page='".$page."', judul='".$judul."', isi_berita='".$news."' WHERE id=".$_GET['id'];
        $result = mysql_query($sqlstr) or die(mysql_error());

        //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
        //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
        $confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";  
    }
    ?>
    <div align="center">
        <div style="width:800px;text-align:left;">
        <script type="text/javascript" src="../../Masterlink/cgoods/ckeditor/ckeditor.js"></script>
        <link href="../../Masterlink/cgoods/ckeditor/content.css" rel="stylesheet" type="text/css"/>
        <?php echo $confirmation;?>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
            <table>
                <tr>
                    <td>Page</td>             
                    <td><select name="static_page">
                    <option value="Pengenalan Perusahaan">Pengenalan Perusahaan</option>
                    <option value="Sejarah Perusahaan">Sejarah Perusahaan</option>
                    <option value="Cabang">Cabang</option>
                    </select></td>

                    <?php // <input size="50px" type="text" name="page" value="<?php echo $page; ?"/> ?>
                </tr>
                <tr>
                    <td>Judul</td>                
                    <td><input size="50px" type="text" name="judul" value="<?php echo $judul; ?>"/></td>
                </tr>
                <tr>
                    <td valign="top">Isi berita</td>              
                    <td>
                        <textarea cols="60" rows="10" id="news" name="news"><?php echo $news;?></textarea>
                        <script type="text/javascript">
                            var editor = CKEDITOR.replace('news');
                        </script>                    </td>
                </tr>
                <tr>             
                    <td><input type="submit" name="ok" value="Simpan"/></td>
              </tr>
            </table>
        </form>
        </div>
    </div>

When I press ok in the form, I expect the result to be "Data telah tersimpan." : "Gagal menyimpan data.";

Instead this appears: "unable to select static_page";

That result suppose to appears when I would like update data not when I want to insert new data.

You are using somewhere $_GET['id'] and somewhere** $_POST['id']**.
so

if (!empty($_GET['id']))//line 15

is always false.So change $_GET to $_POST

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.