有人可以幫我嗎? 即時通訊編輯文章中的圖像,這段代碼的作品,但如果我選擇另一個圖像,舊的仍然在我的文件夾。如何刪除和爲什麼自動輸入數據庫?
第二個問題是如果我不選擇任何圖像,數據庫中的圖像名稱發生更改。它像我選擇圖像,但只有$ randomnewedit被輸入。
if (isset ($_POST['submitedit'])){
$uploads_dir = '../images';
$randomedit = time('YmdHis');
$randomnewedit = $randomedit."_";
$tipe_fileedit = $_FILES['filefotoedit']['type'];
$tmp_fileedit = $_FILES['filefotoedit']['tmp_name'];
$nama_fileedit = $_FILES['filefotoedit']['name'];
$new_nama_fileedit = $randomnewedit.$nama_fileedit;
move_uploaded_file($tmp_fileedit,"$uploads_dir/$new_nama_fileedit");
$namabankedit=trim($_POST['namabankedit']);
$cabangedit=trim($_POST['cabangedit']);
$norekeningedit=trim($_POST['norekeningedit']);
$namanasabahedit=trim($_POST['namanasabahedit']);
$kueri = "UPDATE trans SET namabank='" . $namabankedit. "', cabang='" . $cabangedit. "', rekeningbank='" . $norekeningedit. "', namanasabah='" . $namanasabahedit. "', logobank='" . $new_nama_fileedit. "' WHERE idtrans='" . $idedit . "'";
$hasil = mysql_query($kueri);
echo "<meta http-equiv='refresh' content='0; url=indexcuko.php?module=rekening'>";
}}}
這是我的編輯形式:
if (isset ($_GET['act']) ? $_GET['act']:0){
if ($_GET['act'] == 'edit') {
$idedit = $_GET['id'];
$resultedit = mysql_query("SELECT * FROM trans WHERE idtrans = $idedit;");
$rowedit = mysql_fetch_assoc($resultedit);
$titlenamabank = $rowedit['namabank'];
$titlecabang = $rowedit['cabang'];
$titlerekeningbank = $rowedit['rekeningbank'];
$titlenamanasabah = $rowedit['namanasabah'];
$titlelogobank = $rowedit['logobank'];
echo"
<h1>Edit Rekening</h1>
<form action='' method=\"post\" onreset=\"location.href=rekening.php\" name=\"form2\" enctype='multipart/form-data'>
<table class=\"tableb\">
<tr>
<td width=120 align=center>Nama Bank</td>
<td align=center>:</td>
<td width=120 align=center><input class=\"inputz\" name=\"namabankedit\" id=\"namabank\" type=\"text\" size=\"50\" value=\"$titlenamabank\" /></td>
</tr>
<tr>
<td width=120 align=center>Cabang</td>
<td align=center>:</td>
<td width=120 align=center><input class=\"inputz\" name=\"cabangedit\" id=\"cabang\" type=\"text\" size=\"50\" value=\"$titlecabang\" /></td>
</tr>
<tr>
<td width=120 align=center>No. Rekening</td>
<td align=center>:</td>
<td width=120 align=center><input class=\"inputz\" name=\"norekeningedit\" id=\"norekening\" type=\"text\" size=\"50\" value=\"$titlerekeningbank\" /></td>
</tr>
<tr>
<td width=120 align=center>Atas Nama</td>
<td align=center>:</td>
<td width=120 align=center><input class=\"inputz\" name=\"namanasabahedit\" id=\"namanasabah\" type=\"text\" size=\"50\" value=\"$titlenamanasabah\" /></td>
</tr>
<tr>
<td width=120 align=center>Logo Bank</td>
<td align=center>:</td>
<td width=120 align=center><input name=\"filefotoedit\" id=\"filefoto\" type=\"file\" value=\"$titlelogobank\" /></td>
</tr>
<tr>
<td colspan=\"3\"><button class=\"buttonz\" name=\"submitedit\" type=\"submit\" onClick=\"return verify()\" value=\"save\">Simpan</button></td>
</tr>
</table>
</form>";}}
抱歉,如果說是錯誤的,即時通訊的英語不是很好!
警告:您正在使用已棄用的mysql_ *庫 – user4035
這不會解決您的問題,但出於安全目的,您應該考慮使用預準備語句和參數化查詢。 – bh42
'if(isset($ _GET ['act'])?$ _GET ['act']:0)'double condition,並且不分配任何東西。它應該是$ someVar = isset($ _ GET ['act'])? $ _GET ['act']:0' –