When I try to save the form this error appears:

Unknown column 'image' in 'field list'

Also location & description remains empty. Why is it?

input_image.php

<?php

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

    $id = isset($_POST['id']) ? $_POST['id'] : '';  
    $confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';  
    $productname = isset($_POST['productname']) ? $_POST['productname'] : ''; 
    $location = isset($_POST['location']) ? $_POST['location'] : '';
    $description = isset($_POST['description']) ? $_POST['description'] : '';
    $urlimages = isset($_POST['urlimages']) ? $_POST['urlimages'] : '';


    //Load berita
    if (!empty($_REQUEST['id'])){
        $result = mysql_query("SELECT * FROM gallery WHERE id =".$_REQUEST['id']) or die(mysql_error());
        $data = mysql_fetch_array($result);
        $id = $data['id'];
        $productname = $data['productname'];
        $location = $data['location'];
        $description = $data['description'];
        $urlimages = $data['urlimages'];

    }

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

        if (empty($_REQUEST['id']))
            $sqlstr = "INSERT INTO gallery(productname, location, description, urlimages) VALUES('".$productname."','".$location."','".$description."','".urlimages."')";
        else
            $sqlstr = "UPDATE gallery SET productname='".$productname."', image='".$location."', description='".$description."', urlimages='".$urlimages."' 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>Product Name : </td>
                    <td><input size="30px" type="text" name="productname" value="<?php echo $productname; ?>"/></td>
                </tr>
                <tr>
                    <td>Location :</td>
                    <td><select name="location">
                    <option value="pic1">pic1</option>
                    <option value="pic2">pic2</option>
                    <option value="pic3">pic3</option>
                    <option value="pic4">pic4</option>
                    <option value="pic5">pic5</option>
                    <option value="pic6">pic6</option>
                    <option value="pic7">pic7</option>
                    <option value="pic8">pic8</option>
                    </select></td>
                </tr>
                <tr>
                    <td>Description : </td>
                    <td><textarea rows="4" cols="50"/>

Recommended Answers

All 19 Replies

check your image field, location field, and description field in your table

When uploading files you also need to declare a "enctype".

Also please show the full error, and the lines of code it will refer to

that's the full error message - I also just declare enctype and the error still appears.

hai davy_yg,

in addtion to the above responses,please consider this one

while you inserting data into galley table your sql syntax is like as follows

INSERT INTO gallery(productname, location, description, urlimages).......

but while you updating the gallery table your sql is

UPDATE gallery SET productname='".$productname."', image='".$location."', description='".$description."', urlimages='".$urlimages."' WHERE id=".$_REQUEST['id'];

in update statement we found image column but not in insert statement

please check your gallery table structure once so that your problem will be solved

any comments are appreciated.....

  $sqlstr = "UPDATE gallery SET productname='".$productname."', image='".$location."', description='".$description."', urlimages='".$urlimages."' WHERE id=".$_REQUEST['id'];

You are making heavy work of this, and it's hard to understand, and there is a" missing at the end.

 $request=$_REQUEST['id'];
 $sqlstr = "UPDATE gallery SET productname='$productname', image='$location', description='$description', urlimages='$urlimages' WHERE id='$request' ";

would work better for me, and it's less to type and IMHO, easier to read and check.

Also, when submitting your form, the tag should be

<form action="submit_form.php" method="POST" enctype="multipart/form-data">

That should work ...

And also you have an error with this line;

VALUES('".$productname."','".$location."','".$description."','".urlimages."')";

I think, it should be;

VALUES('".$productname."','".$location."','".$description."','".$urlimages."')";

ok, I do not see the error message any longer. It's just location & description remains empty even after I input the form.

input_image.php

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

        if (empty($_REQUEST['id']))
            $sqlstr = "INSERT INTO gallery(productname, location, description, urlimages) VALUES('".$productname."','".$location."','".$description."','".$urlimages."')";
        else
            $sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' 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" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']?>">
            <input type="hidden" name="id" value="<?php echo $id; ?>"/>
            <table>
                <tr>
                    <td>Product Name : </td>
                    <td><input size="30px" type="text" name="productname" value="<?php echo $productname; ?>"/></td>
                </tr>
                <tr>
                    <td>Location :</td>
                    <td><select name="location">
                    <option value="pic1">pic1</option>
                    <option value="pic2">pic2</option>
                    <option value="pic3">pic3</option>
                    <option value="pic4">pic4</option>
                    <option value="pic5">pic5</option>
                    <option value="pic6">pic6</option>
                    <option value="pic7">pic7</option>
                    <option value="pic8">pic8</option>
                    </select></td>
                </tr>
                <tr>
                    <td>Description : </td>
                    <td><textarea rows="4" cols="50"/></textarea></td>
                </tr>
                <tr>
                    <td>Url Images: </td>
                    <td><input size="30px" type="text" name="judul" value="<?php echo $urlimages; ?>"/></td>                    
                </tr>
                    <td>Images: </td>
                    <td><input size="30px" type="file" name="image" value="<?php echo $image; ?>"/></td>
                <tr><?php // showing the picture ?>
                    <td><img src="photos/<?php echo $image; ?>"/></td>
                </tr>                
                <tr>             
                    <td><input type="submit" name="ok" value="Simpan"/></td>
              </tr>
            </table>
        </form>
        </div>
    </div>

What do you mean by

It's just location & description remains empty even after I input the form.

In the table view:

Product Name    Location    Description Url Images  Action
wheatbread          urlimages   Hapus |Edit

Location & Description remains empty so does in the sql tables. I thought I already fill in in the form so that it fills with some text.

Aaaahh, ok ... Looking at your code, you need to specify what code to excecute. For instance, change

 if (empty($_REQUEST['id']))
            $sqlstr = "INSERT INTO gallery(productname, location, description, urlimages) VALUES('".$productname."','".$location."','".$description."','".$urlimages."')";
        else
            $sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' 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.";  

TO

 if (empty($_REQUEST['id']))
 {
            $sqlstr = "INSERT INTO gallery(productname, location, description, urlimages) VALUES('".$productname."','".$location."','".$description."','".$urlimages."')";
            }
        else
        {
            $sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' 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.";  
        }

Try that and then let us know what the result will be ...

@webville, innit funny how you can look at code for hours, and not spot a missing { !!

I thought it suppose to be like this:

if (isset($_REQUEST['ok'])){

        if (empty($_REQUEST['id']))
            {
            $sqlstr = "INSERT INTO gallery(productname, location, description, urlimages) VALUES('".$productname."','".$location."','".$description."','".$urlimages."')";
            }
        else
            {
            $sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' 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.";  
    }

Yet, I still wonder why location & description is empty. The previous solution that webville suggest does not work either.

$sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' WHERE id=".$_REQUEST['id'];

is still missing the end i.e: WHERE id='".$_REQUEST['id']."';

I change it to:

else
            {
            $sqlstr = "UPDATE gallery SET productname='".$productname."', location='".$location."', description='".$description."', urlimages='".$urlimages."' WHERE id='".$_REQUEST['id']."'"; }

Otherwise there is another error appears. I still yet see the two columns being filled in when I update the data.

Is there any way to trace it where the flaws are?

@TonyG CYPRUS, It is quite funny, but then it happens; especially when you write a code when you are feeling tired or sleepy ...

@davy yg, what error are you getting this tym?

Have you echoed out your post data to ensure that it is actually being sent?
We could all be beating ourselves up over something that's not there to start with.
Mysql can be funny over extra spaces, missing comma's etc.

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.