I want to upload an image through form and save url in database, in 'pic' column. It has been showing errors though it is saving the image name and the image is saving any where in my DB. Your kind answer is highly appreciated. Here is the code:
<?php /* Template Name: Dark Knight*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method="post" enctype='multipart/form-data'>
<p>
<div>
<input name="nametxt" id="nametxt" type="text"><br>
</div>
</p>
<p>
<div>
<input name="fileToUpload" id="fileToUpload" type="file">
</div>
</p>
<input id="submitbtn" type='submit' name='Submit' value='Add Member' /><br><br>
</form>
</div>
</div>
<?php
if(isset($_POST['Submit']))
{
if( isset($_POST['nametxt']) || isset($_FILES['fileToUpload']))
{
global $wpdb;
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]. $_POST['fileToUpload']);
$data = array('name' => $_POST['nametxt'],
'pic' => $target_file);
$table = $wpdb->prefix.'tboxteam';
$format = array('%s','%s');
$wpdb->insert($table,$data,$format);
}
}
?>
Notice: Undefined index: fileToUpload in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\custompage7.php on line 39