Citra45Abadi Citra45Abadi - 3 months ago 11
PHP Question

cannot pass variable with value things.png via GET method in url

I have 4 values I wanna send via GET like this :

<a href="aksi_produk.php?module=produk&act=hapus&id=$r[id_produk]&namafile=$r[gambar]">
Delete
</a>


the URL should looks like this right

website/aksi_produk.php?module=produk&act=hapus&id=198&namafile=thing.png


but instead it looks like this
/aksi_produk.php?module=produk&act=hapus&id=198


I'm missing one value which is
namafile
. it seems I need to use
urlencode()
? but how and where do i need to put it ?

edit

this is the full code for this

$no = $posisi+1;
while($r=mysqli_fetch_array($tampil)){
$tanggal=tgl_indo($r[tgl_masuk]);
$harga=format_rupiah($r[harga]);
$namafile=urlencode($r[gambar]);
echo "<tr><td>$no</td>
<td>$r[nama_produk]</td>
<td align=center>$r[harga]</td>
<td align=center>$r[potongan]</td>
<td align=center>$r[stok]</td>
<td>$tanggal</td>
<td><a
href=?module=produk&act=editproduk&id=$r[id_produk]><img src='images/icn_edit.png' title='Edit'>
</a>
<a
href=$aksi?module=produk&act=hapus&id=$r[id_produk]&namafile=$namafile><img src='images/icn_trash.png' title='delete'>
</a>
</td>
</tr>";
$no++;
}

Answer

please encode before you pass the variable.

$namafile=urlencode($r[gambar]);
<a href="aksi_produk.php?module=produk&act=hapus&id=$r[id_produk]&namafile=$namafile">
Delete
</a>

in the sending page,

$_GET["namafile"]
$file=urldecode($namafile);