Simple code working correctly: Form:
<form name="newad" method="post" enctype="multipart/form-data" action="betterplace.php">
<input type="file" name="delhi" required="required" value="delhi" onchange="javascript:this.form.submit();">
</form>
Action:
$mumbai=$_FILES['image']['tmp_name'];
$sql = " SELECT xyz FROM `dataperiod` WHERE cities LIKE '$mumbai' ";
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
}
/do the stuff
But for making empty property,i assigned isset code to this like:
<?php
if(isset($_POST) && !empty($_POST)) {
$mumbai=$_FILES['image']['tmp_name'];
$sql = " SELECT xyz FROM `dataperiod` WHERE cities LIKE '$mumbai' ";
if(!$result = $conn->query($sql)){
die('There was an error running the query [' . $conn->error . ']');
}
/do the stuff
}
else{
header('location: home.php'); exit();
}
?>
But nothing showing or working.I think problem is not taking post element.Please help.
Do onchange="javascript:this.form.submit();"
firing and redirect to betterplace.php
occurs?
Anyway, isset($_POST)
is wrong, $_POST
is always set, but can be empty, so, as files are always transferred via POST/PUT
, you need just something like:
if (isset($_FILES['delphi'])) {
...
}
Look closer at $_FILES['delphi']
. Yours file input named delphi
, not image
(as u assumed in mumbai=$_FILES['image']['tmp_name'];
):
<input type="file" name="delhi" ... >
So, finally:
<?php
if (isset($_FILES['delphi']) && is_uploaded_file($_FILES['delphi']['tmp_name'])) {
$mumbai = $_FILES['delphi']['tmp_name'];
...
}
Or:
<?php
if (is_uploaded_file($mumbai = @$_FILES['delphi']['tmp_name'])) {
...
}