I wonder why when you try to when you try to update location (lokasi) to Product1 it always saved as Home ?




    $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'] : '';
    $lokasi = isset($_POST['lokasi']) ? $_POST['lokasi'] : '';

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

    else {
    echo "unable to select data";
    echo "id is empty";

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

        if (empty($_POST['id']))
            $sqlstr = "INSERT INTO page(judul, lokasi, isi_berita) VALUES('".$judul."','".$lokasi."','".$news."')";
            $sqlstr = "UPDATE page SET judul='".$judul."', lokasi='".$lokasi."', isi_berita='".$news."' WHERE id=".$_POST['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; ?>"/>
                    <td><select name="judul">
                    <option value="Pengenalan Perusahaan">Pengenalan Perusahaan</option>
                    <option value="Sejarah Perusahaan">Sejarah Perusahaan</option>
                    <option value="Cabang">Cabang</option>

                    <?php // <input size="50px" type="text" name="page" value="<?php echo $page; ?"/> ?>
                    <td><select name="lokasi">
                    <option value="Home">Home</option>
                    <option value="Product1">Product1</option>
                    <option value="Product2">Product2</option>
                    <option value="Product3">Product3</option>
                    <option value="Product4">Product4</option>
                    <option value="Product5">Product5</option>
                    <option value="Product6">Product6</option>
                    <option value="Product7">Product7</option>
                    <option value="Product8">Product8</option>
                    <td valign="top">Isi berita</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>
                    <td><input type="submit" name="ok" value="Simpan"/></td>

Recommended Answers

All 5 Replies

Member Avatar

I wonder why when you try to when you try to update location (lokasi) to Product1 it always saved as Home ?

What is Home anyway? I don't see it anywhere in your code but a word Home?

I only see lokasi code? Unless you didn't post it I don't see any problem with your current code.

Is it solved?

Cek line 69. There is the word Home there.

Member Avatar

Cek line 69. There is the word Home there.

I did look at that and I don't see any code connected to that.

That's why I said I don't see any code related to Home but only the word Home

If you submit your form it will display it again.
The select-stament will preselect the top option by default, that's 'home'.
to chanch this you can do this:
<option value="Product5" selected="selected">Product5</option>
This way the select statmant will always preselect product5

to select the the value the user submited compare it to the value you got:

<option value="Product5" 
<?php if("Product5"==$lokasi) echo'selected="selected"'; ?> 

do this for every option

Be a part of the DaniWeb community

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