This suppose to load my existing data to the form for editing. Yet, this is not the case, I still see the form empty why is it?

The present url: http://localhost/RustoleumCustomCMS/administrator/input_berita_static.php?id=0

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

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

        if (empty($_REQUEST['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=".$_REQUEST['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;?>
Member Avatar for iamthwee

I just LOLLED at your linking to localhost.

It's not clickable. I just trying to show you the value pass through the url. id=0.

Member Avatar for iamthwee

Oh I see...

Ok well simplify it. Echo out the variables. Is it a scope issue. Are they being passed to your form? Is it passing those if statements?

It looks like it doesn't fulfill this condition:

 if (!empty($_REQUEST['id']))

the id is not empty then it suppose to fulfill it right?

Member Avatar for iamthwee

Yes that would be correct...

So either your id is empty or it doesn't recognize the variable.

I'm assuming the id is passed as a url string. I've never used REQUEST before I've always used GET.

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

//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 $isi_berita;
}
else
{
echo "unable to select static_page";
}

I change it to $GET and the message still unable to select static_page so it doesn't fullfil the condition $_GET['id']. How to test and fix this?

Member Avatar for iamthwee

Show us the previous php snippet which calls the GET request then?

This is the first php code for this script. Above it is html. Below it is the script that I posted in my previous post.

<?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'] : '';

You're passing an id with the value 0.

If you read the definition for the function empty, you'll see that 0 is one such value that evaluates as being empty. It will therefore never return true.

Can you not use a non-zero value for the id? If not, you could consider testing for the presence of an integer instead.

commented: holy crap good spot +14

Strange, in the mysql the id is both 0 (integer). How to make it start with 0 and keep incrementing for the next one.

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.