<?php
include "session.php";
$con=mysqli_connect("localhost","root","","project");
if (isset($_POST['submit'])) {
$a=$_POST['title'];
$b=$_POST['catagory'];
$c=$_POST['textarea'];
$g=$_FILES['upload']['name'];
$tmp_name = $_FILES['upload']['tmp_name'];
$d=$_POST['country'];
$e=$_POST['city'];
$f=$_POST['mobilenumber'];
if (isset ($g)) {
if (!empty($g)) {
$location = 'uploads/';
if (move_uploaded_file($tmp_name, $location.$g)){
$query = "insert into productadd(title,catagory,textarea,upload,country,city,mobilenumber) VALUES ('$a','$b','$c','$g','$d','$e','$f')";
$result = mysqli_query($con, $query);
if($result){
$smsg = "Successfully Submitted";
}else{
$fmsg ="Fail";
}
}
}
}
}
mysqli_close($con);
?>
<form action="" method="post" enctype="multipart/form-data">
<div>
<input type = "text" id = "title" name = "title" required placeholder=" " />
<label for ="title"> Title</label>
</div>
<div>
<select name="category" id="select">
<option>--Select Category--</option>
<option>Website</option>
<option>Android App</option>
<option>IOS App</option>
<option>Other</option>
</select>
<label for = "email"> Category</label>
<div class="requirements">
Please Enter category.
</div>
</div>
<div>
<textarea id="textarea" name="textarea" cols="25" rows="7"></textarea>
<label for ="textarea"> Descriptions</label>
</div>
<div>
<input type="file" id="upload" name="upload" placeholder=" " />
<input type="txt" id="name" name="name" placeholder=" " />
</div>
<div>
<select id="country"name="country">
<option value="">Country...</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">Other</option>
</select>
<label for = "country">Country</label>
</div>
<div>
<input type="text" id="city" name="city" required placeholder=" " />
<label for="city">City</label>
</div>
<div>
<input type="text" id="mobilenumber" name="mobilenumber" required placeholder=" " />
<label for="mobilenumber">Mobile #</label>
</div>
<div>
<center>
</div>
<center>
<input type="submit" id="submit" name="submit" value="Submit" />
</center>
</form>
我無法對MySQL數據庫上傳圖片。
代碼在9,10行處給出未定義的索引「上傳」錯誤。但如果我使用if(isset($_FILES['upload'])
,那麼這個錯誤不會顯示出來,但圖像不會上傳到數據庫中。
如果有人知道如何解決這個問題,請給出您的意見。
[PHP: 「注意:未定義變量」, 「注意:未定義指數」 和 「通知:未定義偏移」]的可能的複製(http://stackoverflow.com/questions/4261133/php -notice-undefined-variable-notice-undefined -index-and-notice-undef) –
可能錯誤不在這裏。顯示您的帖子表單或顯示您的HTML代碼您上傳圖像 –
表單代碼有一些命名問題。給我們看一看。你是否有這樣的HTML:-' '也'enctype =「multipart/form-data」'需要格式 –