0

After I press edit on the previous page, it will carries me to this page:

http://localhost/RustoleumCustomCMS/administrator/input_berita_static.php?id=2

//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><input size="50px" type="text" name="page" value="<?php echo $page; ?>"/></td>
                </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>

After I enter all the required information and press submit, the url changes to:

http://localhost/RustoleumCustomCMS/administrator/input_berita_static.php

and this message appears: unable to select static_page

why is it ?

It suppose to update the information.

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by davy_yg
0

First of all, your form sends data using post method and you are cheking for data using $_GET[].
Look at the HTML source of your page and check the URL in the <form method="post" action="URL">, maybe $_SERVER['PHP_SELF'] is the problem.

0

Why would that be a problem? If I press Hapus (delete) then, it should run the top codes in order to delete (still in the same page). If I press edit then it should show me another page. If is incorrect, then what should I change $_SERVER['PHP_SELF'] that into?

        //Hapus berita // undefined index: mode

    echo "<pre>";
    print_r($_REQUEST);
    echo "</pre>";
    if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode']) && $_REQUEST['mode'] == "delete")
        {
        $id = $_REQUEST['id'];
        $result = mysql_query("DELETE FROM static_page WHERE id =".$id) or die(mysql_error());

        $confirmation = !$result ? "Gagal menghapus data." : "Data telah terhapus."; 
        }
    else
        {
        $confirmation = "No change performed";
        } 

?>
<div align="center">
    <div style="width:700px;text-align:left;padding-top:5px;">
        <?php  if (isset($confirmation)) { echo $confirmation; } ?>  
        <form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">

Edited by davy_yg

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.