Form
Code:
<div class="posting">
<form action="post.php" method="post" enctype="multipart/form-data" name="FUpload" id="FUpload">
<table width="400px" >
<th colspan="3" align="left" ><div style="margin:0 0 0 20px"><h4>Posting Produk Penjualan</h4></div></th>
<tr>
<td><label for="title">Judul</label></td>
<td><input name="judul" id="judul"" /></td>
</tr>
<tr>
<td><label for="body">Tulisan</label></td>
<td><textarea rows="10" cols="50" name="body" id="body"></textarea></td>
</tr>
<tr>
<td><label for="gambar">Link gambar Produk</label></td>
<td><input name="gambar" type="file" id="gambar"></input></td>
</tr>
<tr>
<td></td>
<td><input class="btn btn-primary" type="submit" value="post" /></td>
</tr>
</table>
</form>
</div>
<?php include 'footer.php'; ?>
Prosses
Code:
<?php
$namafolder="gambar/"; //tempat menyimpan file
$con=mysql_connect("mysql.idhostinger.com","u394473222_wew12","qwe123") or die("Gagal");
mysql_select_db("u394473222_wew") or die("Gagal");
if (!empty($_FILES["gambar"]["tmp_name"]))
{
$jenis_gambar=$_FILES['gambar']['type'];
$judul=$_POST['judul'];
$body=$_POST['body'];
if($jenis_gambar=="image/jpeg" || $jenis_gambar=="image/jpg" || $jenis_gambar=="image/gif" || $jenis_gambar=="image/x-png")
{
$gambar = $namafolder . basename($_FILES['gambar']['name']);
if (move_uploaded_file($_FILES['gambar']['tmp_name'], $gambar))
{
echo "Gambar berhasil dikirim ".$gambar;
$sql="insert into post ('judul','body','gambar')
values ('$judul','$body','$gambar')";
$res=mysql_query($sql) or die (mysql_error());
} else {
echo "Gambar gagal dikirim";
}
} else {
echo "Jenis gambar yang anda kirim salah. Harus .jpg .gif .png";
} } else {
echo "Anda belum memilih gambar";
}
?>
Error
Code:
Gambar berhasil dikirim gambar/1.jpgYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''judul','body','gambar') values ('as','dasdasd','gambar/1.jpg')' at line 1
SQL
Mohon bantuannya
Share This Thread