0

product_edit.php

<?php 

$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".$_REQUEST['id']. "', p.kategori_id = k.kategori_id") or die(mysql_error());
$data = mysql_fetch_array($result);

// cari syntax sql yang pas
//$result_kat = mysql_query("SELECT * FROM kategori WHERE id_produk=".$_REQUEST['id']) or die(mysql_error());
//$data_kat = mysql_fetch_array($result);

?>

<form method = "POST" enctype="multipart/formdata" action = "<?php $_SERVER['PHP_SELF'] ?>"> 
<table border="0" cellpadding="2">

        <tr>
        	<td>Nama</td>
        	<td><input name="nama" type="text" value = <?php echo $data['nama_produk']; ?> size="20" />
        </tr>
        <tr>
        	<td>Kategori</td>
         	<td><select name=“select”>
			<option value=“kategori”>Kategori</option></select></td>

</td>
        </tr>
        <tr>
        	<td>Harga</td>
            <td><input name="harga" type="text" value = <?php echo $data['harga']; ?>></td>
        </tr>
        <tr>
        	<td>Deskripsi</td>
            <td><textarea name="deskripsi" cols="30" rows="15" value = <?php echo $data['deskripsi']; ?></textarea>
            <script type="text/javascript">
					var editor = CKEDITOR.replace('deskripsi');
			</script>	
            
            </td>
        </tr>
        <tr>
        	<td>Gambar</td>
			<td><img src="foto_produk/<?php echo $data['gambar'];?>" width="30%" height="30%" /></td>            
        </tr>	
		<tr>
        	<td>Ganti Gambar</td>
            <td>
            <input name="uploaded_file" type="file" value="Browse" /></td>
            </form>
        </tr>	
        <tr>
        	<td></td>
            <td><br /><center><input name="save" type="button" value="Simpan" /></center></td>
        </tr>
	</tr>

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' p.kategori_id = k.kategori_id' at line 1


What's wrong with SQL Syntax?

$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".$_REQUEST['id']. "', p.kategori_id = k.kategori_id") or die(mysql_error());

I am using this SQL syntax for my combo box in:

<td>Kategori</td>
         	<td><select name=“select”>
	<option value=“kategori”>Kategori</option></select></td>

The category is in different table (kategori table) then the rest of the field (product table). I am trying to link the table by using kategori_id

Edited by davy_yg: n/a

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

Try to clean the query variable $_REQUEST. if it has an apostrophe, then the resulting query string will have an odd number of apostrophes resulting in the mysql error.
You can use:

mysql_real_escape_string($_REQUEST['id'])

in place of

$_REQUEST['id']

.
All the best

Edited by roottybrian: n/a

0

The error remains.

$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".mysql_real_escape_string($_REQUEST['id'])."', p.id_kategori = k.id_kategori") or die(mysql_error());

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' p.id_kategori = k.id_kategori' at line 1

id_kategori is in the same variable setting both in produk and in kategori (INT(5)). It is primary key in kategori and normal key in produk.

Edited by davy_yg: n/a

This question has already been answered. 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.