簡體   English   中英

PHP-無法將圖像名稱添加到數據庫表

[英]PHP - Cant add image name to Database Table

請解釋一下

我面臨的問題是無法將圖像名稱添加到數據庫表中……它添加了隨機數,但沒有圖像名稱

數據庫連接和插入數據代碼

        $inst="insert into addgall set 
                id='".$_POST['id']."',
                title='".$_POST['title']."',
                tag1='".$_POST['tag1']."',
                image='".$name."'
                ";

mysql_query($inst);     
}
}
else
{
$sel="select * from addgall where id='".$_GET['upid']."' ";
$exe=mysql_query($sel);
$fetch=mysql_fetch_array($exe);
if($_POST['login']=='Add')
{
$rand=rand(10,99999999);
$name=$rand.$_FILES['image']['name'];
$tmppath=$_FILES['image']['tmp_name'];
$path="images/portfolio/".$name;
move_uploaded_file($tmppath,$path);
unlink("images/portfolio/".$fetch['image']);

echo $inst="update addgall set
       title='".$_POST['title']."',
       image='".$name."'
       where id='".$_GET['upid']."'" ;

         mysql_query($inst);

    echo '<script>window.location="Viewgallery.php"</script>';
}
}
?>

這是表格代碼

<form name="contactForm" id='contact_form' method="post" action=''>
                            <div class="row">
                                <div class="col-md-6">
                                    <div id='name_error' class='error'>Unique ID of Product</div>
                                    <div>
                                        <input type='text' name='id' id='name' class="form-control" placeholder="Unique ID of Product">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div id='name_error' class='error'>Title of the Product</div>
                                    <div>
                                        <input type='text' name='title' class="form-control" placeholder="Title of the Product">
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <div id='name_error' class='error'>Tag</div>
                                    <div>
                                        <input type='text' name='tag1' class="form-control" placeholder="Tags seperated by 1 space">
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <div id='name_error' class='error'>Tag</div>
                                    <div>
                                        <input type='file' name='image' class="form-control" placeholder="Tags seperated by 1 space">
                                    </div>
                                </div>

                                <div id='mail_success' class='success'>Your message has been sent successfully.</div>
                                <div id='mail_fail' class='error'>Sorry, error occured this time sending your message.</div>
                                <div class="col-md-12">
                                <br>
                                    <p id='submit'>
                                        <input type='submit' value='Add' name='login' class="btn btn-border">
                                    </p>
                                </div>
                            </div>
                        </form>

您已經在表單標簽中忽略了enctype = multipart / form-date ,因此在表單標簽中添加enctype屬性將解決您的問題

<form name="contactForm" id='contact_form' method="post" action='' enctype= 'multipart/form-data'>

form標簽中添加enctype= multipart/form-data

<form name="contactForm" id='contact_form' method="post" action='' enctype= 'multipart/form-data'>

將enctype =“ multipart / form-data”添加到您的表單元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM