I have getting this error " Notice: Undefined variable: lic_photo in /opt/lampp/htdocs/11/licence.php on line 60" while I trying to upload a file into the database.
<?php
session_start();
include('conn.php');
if(isset($_POST["submit"])){
$lic_no=$_POST["lr-ln"];
$lic_date=$_POST["lr-date"];
$lc_name=$_POST["lr-name"];
$lic_guard=$_POST["lr-guard"];
$lic_dob=$_POST["lr-dob"];
$lic_blood=$_POST["lr-blood"];
$lic_rhfactor=$_POST["lr-rh"];
$lic_paddress=$_POST["lr-paddr"];
$lic_taddress=$_POST["lr-taddr"];
$lic_mark1=$_POST["lr-mark1"];
$lic_mark2=$_POST["lr-mark2"];
/*uploading photos and signature to the datebase
--------------------------------------------------*/
if (isset($_FILES["lr_photo"]["name"])) {
$lic_photo = $_FILES["lr_photo"]["name"];
$ptmp_name = $_FILES['lr_photo']['tmp_name'];
$perror = $_FILES['lr_photo']['error'];
if (!empty($lic_photo)) {
$plocation = 'uploads/photos';
if (move_uploaded_file($ptmp_name, $plocation.$lic_photo)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
if (isset($_FILES["lr_sig"]["name"])) {
$lic_signature = $_FILES["lr_sig"]["name"];
$stmp_name = $_FILES['lr_sig']['tmp_name'];
$serror = $_FILES['lr_sig']['error'];
if (!empty($lic_signature)) {
$slocation = 'uploads/photos';
if (move_uploaded_file($stmp_name, $slocation.$lic_signature)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
/* entering data into mySQL database
------------------------------------------------*/
$sql = "insert into licence values ('$lic_no','$lic_date','$lc_name','$lic_guard','$lic_dob','$lic_blood','$lic_rhfactor'.'$lic_paddress','$lic_taddress',
'$lic_mark1','$lic_mark2','$lic_photo','$lic_signature')";
mysqli_query($conn,$sql);
echo "<script>alert('registerd suceessfully')
</script>";
}
?>
This is the code that I runned.when I declare the variable name in the declaring section.It shows no error but the data is not entering in to the database.
<?php
session_start();
include('conn.php');
if(isset($_POST["submit"])){
$lic_no=$_POST["lr-ln"];
$lic_date=$_POST["lr-date"];
$lc_name=$_POST["lr-name"];
$lic_guard=$_POST["lr-guard"];
$lic_dob=$_POST["lr-dob"];
$lic_blood=$_POST["lr-blood"];
$lic_rhfactor=$_POST["lr-rh"];
$lic_paddress=$_POST["lr-paddr"];
$lic_taddress=$_POST["lr-taddr"];
$lic_mark1=$_POST["lr-mark1"];
$lic_mark2=$_POST["lr-mark2"];
$lic_photo=1;
$lic_signature=2;
/*uploading photos and signature to the datebase
--------------------------------------------------*/
if (isset($_FILES["lr_photo"]["name"])) {
$lic_photo = $_FILES["lr_photo"]["name"];
$ptmp_name = $_FILES['lr_photo']['tmp_name'];
$perror = $_FILES['lr_photo']['error'];
if (!empty($lic_photo)) {
$plocation = 'uploads/photos';
if (move_uploaded_file($ptmp_name, $plocation.$lic_photo)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
if (isset($_FILES["lr_sig"]["name"])) {
$lic_signature = $_FILES["lr_sig"]["name"];
$stmp_name = $_FILES['lr_sig']['tmp_name'];
$serror = $_FILES['lr_sig']['error'];
if (!empty($lic_signature)) {
$slocation = 'uploads/photos';
if (move_uploaded_file($stmp_name, $slocation.$lic_signature)){
echo 'Uploaded';
}
} else {
echo 'please choose a file';
}
}
/* entering data into mySQL database
------------------------------------------------*/
$sql = "insert into licence values ('$lic_no','$lic_date','$lc_name','$lic_guard','$lic_dob','$lic_blood','$lic_rhfactor'.'$lic_paddress','$lic_taddress',
'$lic_mark1','$lic_mark2','$lic_photo','$lic_signature')";
mysqli_query($conn,$sql);
echo "<script>alert('registerd suceessfully')
</script>";
}
?>
The above code shows no error but the data is not entering into the database.
Aucun commentaire:
Enregistrer un commentaire