Is it has method to save <img src="XXXXX"> image path to database using PHP. Why src path doesn't pick in PHP . My PHP code is
<?php
include('conn.php');
if(!empty($_POST["submit1"]) || isset($_POST["submit1"])){
if (isset($_POST['img1'])) {
$filename1= $_POST['img1'];
}
if (isset($_POST['img2'])) {
$filename2= $_POST['img2'];
}
}
?>
And my html code is
<html>
<head>
<title>Test
</title>
</head>
<body>
<form action="phpscript/test.php" method="post" enctype="multipart/form-data">
<div>Images </div>
<input type="file" id="file" name="file">
<div class="row align-text-center">
<div class="col-sm2">
<input type="image" id="img1" name="img1" src="img/1.jpg" width="150" height="150" style="border: "/>
</div>
<div class="col-sm2">
<input type="image" src="img/2.jpg" width="150" height="150" id="img2" name="img2" style="border: " />
</div>
<div class="col-sm2">
<button class="btn " type="submit" id="submit1" name="submit1">Submit</button>
</form>
</body>
</html>
Actually I need to pick image path in php code.But in php code $filename1 and $filename2 values are NULL.Is it another method to get image path in php code?
var_dump($_FILES);to see, what variables it has?$_FILES['img1']exist? Your form field with that name is not a file upload field, it is just atype="image"field. Those do not send any file names.type="image"does. Thesrc-attribute is for how the element should look, it won't be submitted with the form$_POST['img1']also wouldn't be the file, take a look at php.net/manual/en/features.file-upload.post-method.php