php undefined index with multiple file upload - php

I have this code but I can't get what's wrong with it. Any help will be appreciated. Please don't be too quick to mark it as a duplicate without giving me a solution as I have been through all question that are similar and they do not answer my problem as I have already checked if file is uploaded be for processing it and still get this error UNDEFINED INDEX:
Html code:
<!DOCTYPE html>
<html>
<body>
<form role="form" method="post" action="test2.php">
<div class="form-group">
<div class="row">
<div class="col-xs-8">
<label class="control-label">Call Sign</label>
<input type="text" class="form-control" name="call_sign" />
</div>
<div class="col-md-4">
<label class="control-label">Picture</label>
<img src="Koala.jpg" alt="with responsive image feature" class="img-responsive img-circle">
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Driver First Name</label>
<input type="text" class="form-control" name="first_Name" />
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Driver Last Name</label>
<input type="text" class="form-control" name="last_Name" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-8">
<label for = "fileToUpload">File input</label>
<input type="file" name="fileToUpload" id="fileToUpload" >
</div>
</div>
<div class="row">
<div class="col-xs-8">
<label class="control-label">Location</label>
<input type="text" class="form-control" name="Location" />
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">Company Shirt</label>
<select class="form-control" name="CShirt">
<option value="">Choose </option>
<option value="Good">Good</option>
<option value="Poor">Poor</option>
<option value="UniformNotWorn">Uniform Not Worn</option>
<option value="Untidy">Untidy</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">Trousers</label>
<select class="form-control" name="Trousers">
<option value="">Choose </option>
<option value="Clean/Smart">Clean/Smart</option>
<option value="Acceptable">Acceptable</option>
<option value="Jeans/Casual">Jeans/ Casual</option>
<option value="Untidy">Untidy</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-4 selectContainer">
<label class="control-label">General Appearance</label>
<select class="form-control" name="Appearance">
<option value="">Choose </option>
<option value="Good">Good</option>
<option value="Fair">Fair</option>
<option value="Poor">Poor</option>
</select>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="control-label">In the Vehicle</label>
<div class = "checkbox">
<label><input type = "checkbox" value="Tea/Coffe" name="In_the_Vehicle"> Tea/Coffe</label>
</div>
<div class = "checkbox">
<label><input type = "checkbox" value="Eating" name="In_the_Vehicle"> Eating</label>
</div>
<div class = "checkbox">
<label><input type = "checkbox" value="Smoking" name="In_the_Vehicle"> Smoking</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Assessor Comments</label>
<div>
<textarea class="controlline" name="Assessor_Comments" rows="8"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label">Driver Comments</label>
<div>
<textarea class="controlline" name="Driver_Comments" rows="8"></textarea>
</div>
</div>
<div class="form-group">
<label class="control-label">Kit Required</label>
<div>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="DMN Shirts" /> DMN Shirts
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="DMN Jacket" /> DMN Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="BMW Jacket" /> BMW Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Hi-Viz-Jacket" />Hi-Viz-Jacket
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="ID Badge" /> ID Badge
</label>
</div>
</div>
<div class="form-group">
<div>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Tyre_Guage" /> Tyre Guage
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="Trade_Plate_Bands" /> Trade Plate Bands
</label>
<label class="radio-inline">
<input type="radio" name="Kit_Required" value="MiVIS_Ruler/Kit" /> MiVIS Ruler/Kit
</label>
</div>
</div>
<div class="form-group">
<label class="control-label">Training Wanted</label>
<div>
<label class="radio-inline">
<input type="radio" name="Training_Wanted" value="Yes" /> Yes
</label>
<label class="radio-inline">
<input type="radio" name="Training_Wanted" value="No" /> No
</label>
</div>
</div>
<button type="submit" class="button" name="submit">Submit</button>
</form>
</body>
</html>
php code:
if (isset($_POST['submit'])) {
$query = "INSERT INTO spot_checkdetails(location,CShirt,trouser,appearance,kitReq,Training,fk1_callSIgn)
VALUES('$_POST[Location]','$_POST[CShirt]' ,'$_POST[Trousers]' ,'$_POST[Appearance]','$_POST[Kit_Required]' ,'$_POST[Training_Wanted]','$_POST[call_sign]')";
$result = mysqli_query($connection, $query);
if (!$result) die("database acess failed".$connection->error);
$foreignk = "select id from spot_checkdetails order by id desc limit 1";
$result = mysqli_query($connection, $foreignk);
while ($row = $result->fetch_assoc()) {
$reqry = $row["id"];
}
$query = "INSERT INTO spotcheckcomment(assCom,driCom,spot_checkdetails_id)VALUES('$_POST[Assessor_Comments]','$_POST[Driver_Comments]','".$reqry."')";
$result = mysqli_query($connection, $query);
$foreign2 = "select id from spotcheckcomment order by id desc limit 1";
$result = mysqli_query($connection, $foreign2);
while ($row = $result->fetch_assoc()) {
$reqry2 = $row["id"];
}
$foreign3 = "select fk1_callSIgn from spot_checkdetails order by id desc limit 1";
$result = mysqli_query($connection, $foreign3);
while ($row = $result->fetch_assoc()) {
$reqry3 = $row["fk1_callSIgn"];
}
if (!empty($_POST)) { // **check weather the form is submitted or not**
// Where the file is going to be placed
$target_path = "uploads/";
$random_digit = rand(0000, 9999)."_";
$jobnumber = $reqry3."_".$random_digit;
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
$new_file_name = $jobnumber.basename($_FILES["fileToUpload"]["name"]);
//$target_file = $target_dir .$new_file_name;
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.$new_file_name; // basename( $_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path)) {
echo "The file ".basename($_FILES['fileToUpload']['name']).
" has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
}
$query = "INSERT INTO spotcheckimagepath(imgname,imagepath,spot_check_comment_id)VALUES('".$new_file_name."','".$target_path."','".$reqry2."')";
$result = mysqli_query($connection, $query);
}
?>
the ERROR:) Notice: Undefined index: fileToUpload in

As w3schools.com says you need to add enctype="multipart/form-data" to you form.
multipart/form-data
No characters are encoded. This value is required when you are using forms that have a file upload control
So change this line
<form role="form" method="post" action="test2.php">
to this one
<form role="form" method="post" action="test2.php" enctype="multipart/form-data">
Also you can see here how check if image was uploaded

Change the following:
<form role="form" method="post" action="test2.php">
to
<form role="form" method="post" action="test2.php" enctype="multipart/form-data">
Would also check if var exists before trying to access it, can use
if(isset($_FILES['fileToUpload']){do something}else{error!}
Additionally suggest you move your PHP code before the html.

Related

Show data after receiving from database PHP

This is my PHP code, which will display data when I click the button. I want to display the data for the specified card when I click the button for the number 1. I want to display all information in card 1, but my code will display all information. Can anyone help me?
http://www.m9c.net/uploads/15678158911.png
<? $title= 'Show CV';
$quariy = ("select * from information where selector ='2'");
$result = mysqli_query($mysqli, $quariy) or die("database
error:". mysqli_error($mysqli));
while ($data = mysqli_fetch_assoc($result)) {?>
<form action="" method = "post" class= "pl-4 pr-4">
<div class="card">
<div class="card-body">
<div class="form-group">
<label for="name">Your Name</label>
<input type="text" class="form-control" name="name"
value="<?php echo $data['name'] ?>">
</div>
<div class="form-group">
<label for="education">Your Education</label>
<input type="text" class="form-control"
name="education" value="<?php echo $data['education']?>" >
</div>
<div class="form-group">
<label for="contact_information"> Contact
Information </label>
<textarea class="form-control"
name="contact_information" rows="3"><?php echo
$data['contact_information'] ?></textarea></div>
<div class="form-group">
<label for="skills">Skills</label>
<textarea class="form-control" name="skills"
rows="3"><?php echo $data['skills'] ?></textarea>
</div>
<div class="form-group">
<label for="work">Work Experiences </label>
<textarea class="form-control" name="work"
rows="3">
<?php echo $data['work'] ?></textarea></div>
<div class="form-group">
<label for="projects">Projects </label>
<textarea class="form-control" name="projects"
rows="3"><?php echo $data['projects'] ?>
</textarea>
</div></div><?php }?></form>

Bootstrap nav-tabs not working with php script

My nav-tabs works fine using static data for my dropdown list but when I add the script to populate the dropdown list, the tabs don't work anymore.
I don't think there's any problem with the query since the list gets populated. Probably with the echo?
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active">Boarding House Info</li>
<li>Other Info</li>
<li>Location</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1">
<div class="box-body">
<div class="form-group">
<label for="boarding-house-name">Boarding House Name</label>
<input type="text" class="form-control" id="bh-name" name="bh-name" placeholder="boarding house name">
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="price">Price</label><br>
<div class="col-md-2" style="margin-left:-15px;">
<input type="text" class="form-control" id="pricemin" name="bh-pricemin" placeholder="min">
</div>
<div class="col-md-2" style="margin-left:-15px;">
<input type="text" class="form-control" id="pricemax" name="bh-pricemax" placeholder="max">
</div>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="bh-address" placeholder="address">
</div>
<div class="form-group">
<label for="barangay">Barangay</label>
<select class="form-control" name="bh-barangay">
<option value="Brgy 1">Brgy 1</option>
<option value="Brgy 2">Brgy 2</option>
<option value="Brgy 3">Brgy 3</option>
<option value="Brgy 4">Brgy 4</option>
</select>
</div>
<div class="form-group">
<label for="contactperson">Contact Person</label>
<input type="text" class="form-control" id="contactperson" name="bh-contactperson" placeholder="contact person">
</div>
<div class="form-group">
<label for="contactnumber">Contact Number</label>
<input type="text" class="form-control" id="contactnumber" name="bh-contactnumber" placeholder="contact number">
</div>
<div class="form-group">
<label for="owner">Owner</label>
<select class="form-control" name="bh-owner-id">
<?php
$query = "SELECT id_owner, owner_name FROM tbl_owner";
$result = $conn->query($query) or die("Connection failed: " . $conn->connect_error);
while($row = mysqli_fetch_assoc($result)) {
echo "<option value='".$row['id_owner']."'>".$row['owner_name']."</option>";
} mysql_free_result($result);
?>
</select>
</div>
</div>
</div>
<div class="tab-pane" id="tab_2">
<div class="box-body">
<div class="form-group">
<label for="tenant" style="margin-bottom:-15px;">Tenant</label>
<div class="checkbox">
<label class="checkbox-inline">
<input type="checkbox" id="tenant_checkbx" value="Male"> Male
</label>
<label class="checkbox-inline">
<input type="checkbox" id="tenant_checkbx" value="Female"> Female
</label>
</div>
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="specification">Specification</label><br>
<div class="col-md-6" style="margin-left:-15px;">
<select class="form-control">
<option>Boarding House</option>
<option>Dormitory</option>
<option>Apartelle</option>
<option>Lodge</option>
<option>Motel</option>
</select>
</div>
</div>
<div class="form-group" style="margin-bottom:50px">
<label for="noofrooms">No. of Rooms</label><br>
<div class="col-md-6" style="margin-left:-15px;">
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="# of rooms">
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="curfew">Curfew</label>
<div class="radio">
<label>
<input type="radio" name="curfew_radio" id="curfew_yes" value="Yes" checked> Yes
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="curfew_radio" id="curfew_no" value="No"> No
</label>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="guests">Guests</label>
<div class="radio">
<label>
<input type="radio" name="guests_radio" id="guests_yes" value="Yes" checked> Yes
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="guests_radio" id="guests_no" value="No"> No
</label>
</div>
</div>
</div>
<div class="col-md-2">
<div class="form-group" style="margin-left:-15px;">
<label for="crtype">CR Type</label>
<div class="checkbox">
<label>
<input type="checkbox" id="crtype_checkbx" value="Private"> Private
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="crtype_checkbx" value="Public"> Public
</label>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="tab_3">
<div class="box-body">
<!-- INSERT MAP HERE -->
</div>
</div>
</div>
</div>
Here is the query php script I used to populate the owner dropdown list:
<?php
$query = "SELECT id_owner, owner_name FROM tbl_owner";
$result = $conn->query($query) or die("Connection failed: " . $conn->connect_error);
while($row = mysqli_fetch_assoc($result)) {
echo "<option value='".$row['id_owner']."'>".$row['owner_name']."</option>";
} mysql_free_result($result);
?>
It's working now. Did some more debugging with the script and it seems like the line:
mysql_free_result($result);
(after the while condition) is the culprit.
I removed it and the tabs are working now. :)

Multi input type text to mysql php

I am trying to pass 5 values in same time using this code.
There is an error in strip_tags. Can any one tell me how to solve it,
php code >
$option = strip_tags($_POST['option']);
$survey_name = strip_tags($_POST['survey_name']);
if(isset($_POST['sendv'])){
if($option) {
foreach($option as $o){
$resource = mysql_query("INSERT INTO options
(value,ques_id)
VALUES
('$o','$survey_name')
"
)or die(mysql_error());}
html code >
<form action="" method="post" >
<div class="form-group">
<label for="email">Option 1</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 2</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 3</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Option 4</label>
<input type="text" class="form-control" name="option[]">
</div><div class="form-group">
<label for="email">Option 5</label>
<input type="text" class="form-control" name="option[]">
</div>
<div class="form-group">
<label for="email">Survey name</label>
<select class="form-control" name="survey_name" >
<option value="1" >1</option>
</select>
</div>
<button type="submit" name="sendv" class="btn btn-default">Add</button>
</form>
When I post it, this error appears..
strip_tags() expects parameter 1 to be string, array given in

I have added php page to get connected to database i dint get loaded the the php page once submitted .neither stores data to database nor displays

i am trying to get connected to database .html page doesnt get connected to addtodatabase.php which has many feilds like radio button,checkbox,textarea, input field .Once given submit it doesn't display the data .
<form action="addtodatabase.php" method="post">
<div class="container">
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="Firstname" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
</div>
</form>
.....
...
<button type="submit" class="btn btn-default">Submit</button>
addtodatabase.php page as phpmyadmin username as root , pasword NULL
<?php
$connection = mysql_connect ('root','','');
mysql_select_db('form_db');
$Firstname = $_POST ['Firstname'];
$Secondname = $_POST ['Secondname'];
echo $_POST['Firstname'];
echo '<br />';
echo $_POST['Secondname'];
$query =
"INSERT INTO form_details
(Firstname,Secondname)
values
('$Firstname','$Secondname')";
$result = mysql_query($query);
Echo "Database Saved";
mysql_close($connection);
?>
i have change the code from mysql to mysqli
<?php
$connect=mysqli_connect('localhost','root','','form_db');
if(mysqli_connect_errno($connect))
{
echo 'Failed to connect';
}
$Firstname = $_POST ['Firstname'];
$Secondname =$_POST ['Secondname'];
echo $_POST['Firstname'];
echo '<br />';
echo $_POST['Secondname'];
$query =
"INSERT INTO form_details
(Firstname,Secondname)
values
('$Firstname','$Secondname')";
$result = mysqli_query($query);
if(mysqli_affected_rows($connect) > 0){
echo "<p>Employee Added</p>";
echo "Go Back";
} else {
echo "Employee NOT Added<br />";
echo mysqli_error ($connect);
}
?>
Even after changing to mysqli it not working .addtodatabase.php
I am getting this error Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\Form\addtodatabase.php on line 2
My entire form looks this way
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="customstyle.css">
</head>
<body>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<form action="addtodatabase.php" method="post">
<div class="container">
<h1> Group of Companies</h1>
<h3> ICT & Security Department User Registration form </h3>
<h4> To be filled by HR department for New Employee </h4>
<form class="form-inline">
<fieldset>
<legend>Security Department User Registration</legend>
<div class="form-group">
<label for="Firstname">First Name</label>
<input type="text" class="form-control" id="Firstname" name="Firstname" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Secondname">Second Name</label>
<input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
</div>
</form>
<form >
<div class="form-group">
<label for="location">Dpt./Location</label>
<input type="text" class="form-control" name="location" id="location" placeholder="Text input">
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="Designation">Designation</label>
<input type="text" class="form-control" id="Designation" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Fileno">File No</label>
<input type="text" class="form-control" id="Fileno" placeholder="Password"><br/>
</div>
</form>
<form class="form-inline">
<div class="form-group">
<label for="Dateofapplication">Date of Application</label>
<input type="text" class="form-control" id="Dateofapplication" placeholder="Text input"><br/>
</div>
<div class="form-group">
<label for="Dateofjoining">Date of Joining</label>
<input type="text" class="form-control" id="Dateofjoining" placeholder="Password"><br/>
</div>
</form>
<form>
<fieldset>
<legend>For Head office staffs only </legend>
<label>Card Type:</label>
<div id="idcard">
<label class="checkbox-inline">
<input type="checkbox" value="">Trainee ID Card
</label>
<label class="radio-inline">
<input type="radio" name="green">Green
</label>
<label class="radio-inline">
<input type="radio" name="red">Red
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Permanent ID Card
</label>
</div>
<div class="aligncheckbox">
<label>Door Access:</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Main
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Finance Division
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Meeting Room
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Goods Receiving
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Graphics & Media
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">IT Dept
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Server Room
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Dist.&Quality Control
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Warehouse Supervisor
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Pur.Office Meeting Room
</label>
</div>
<div class="aligncheckbox">
<label class="checkbox-inline">
<input type="checkbox" value="">Purchase Office
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Exit
</label>
</div>
<!-- <div class="upload">
<label for="Passportcopy">Passport Copy</label>
<input type="file" id="Passportcopy">
<label for="Photo">Photo</label>
<input type="file" id="Photo">
</div>
<div>
<label class="checkbox-inline">
<input type="checkbox" value="">Finger Registration
</label>
</div> -->
<div class="container">
<div id="upload row">
<form class="form-inline">
<div class="form-group col-xs-*">
<label for="Passportcopy">Passport Copy</label>
<input type="file" class="form-control" id="Passportcopy">
</div>
<div class="form-group col-xs-*">
<label for="Photo">Photo</label>
<input type="file" class="form-control" id="Photo">
</div>
</form>
</div>
</div>
</form>
<!-- second form IT department -->
<div class="secform">
<form>
<fieldset>
<legend>IT Department User Registration </legend>
<div class="container">
<form class="form-inline">
<div class="checkbox-inline" id="erp">
<label><input type="checkbox" value="">Enroll as sales Person ERP</label>
</div>
<div class="form-group" id="textbox">
<label for="erpmodules">ERP Modules</label>
<textarea class="form-control" rows="5" id="erpmodules"></textarea>
</div>
</fieldset>
</form>
<form>
<fieldset>
<legend>For Head office staffs only </legend>
<div class="fkhaccess">
<div class="form-group" id="textbox">
<label for="fkhaccess">FKH Folder Access</label>
<textarea class="form-control" rows="5" id="fkhaccess"></textarea>
</div>
<div class="container-fluid">
<ul id="access">
<li> <label>Internet Access</label></li>
<li>
<label class="radio-inline">
<input type="radio" name="yes">Yes
</label></li>
<li>
<label class="radio-inline">
<input type="radio" name="no">No
</label></li>
</ul>
<ul id="purpose">
<li><p>If yes, Purpose </p></li>
<li>
<div class="form-group" id="textbox">
<label for="purpose">Job Purpose</label>
<textarea class="form-control" rows="5" id="purpose"></textarea>
</div></li>
</ul>
<ul id="compmail">
<li>
<div class="form-group" id="textbox" >
<label for="companyemail">Company Email</label>
<textarea class="form-control" rows="5" id="companyemail"></textarea>
</div></li>
</ul>
<form class="form-inline">
<label> Computer facilities: </label>
<label> CD ROM </label>
<label class="checkbox-inline">
<input type="checkbox" value="">Read
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Write
</label>
<label> USB PORTS </label>
<label class="checkbox-inline">
<input type="checkbox" value="">Read
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Write
</label>
</form>
<form class="form-inline">
<label class="checkbox-inline" id="label1">
<input type="checkbox" value="">Parallel Port
</label>
</form>
<form class="form-inline">
<label> Printers </label>
<label class="checkbox-inline">
<input type="checkbox" value="">MP2352(Front Office)
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">MP2501(Purchase)
</label>
</form>
<form class="form-inline">
<label class="checkbox-inline">
<input type="checkbox" value="">MP1600(MD Office)
</label>
<label class="checkbox-inline">
<input type="checkbox" value="">DSM616(Finance)
</label>
</form>
<form class="form-inline">
<ul><li>
<label> Computer Utilities :</label>
<label class="checkbox-inline">
<input type="checkbox" value="">Scanner
</label></li>
<li>
<label class="checkbox-inline">
<input type="checkbox" value="">Barcode Scanner
</label></li>
<li>
<label class="checkbox-inline">
<input type="checkbox" value="">Others
</label></li>
<ul id="software">
<li>
<div class="form-group" id="textbox" >
<label for="softwarerequired">Software Required </label>
<textarea class="form-control" rows="5" id="software"></textarea>
</div></li>
</ul>
</form>
</div>
</div>
</fieldset>
</form>
<div >
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(HR)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(Admin Manager)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
</div>
<div class="fill">
<div class='sign-container'>
<div class="div1">Form Filled by</div>
<div class='sign'> </div>
<div class="div2"> </div>
<div class="div3">(IT Manager)</div>
</div>
</div>
<div class="sign-box">
<p id="signbox"> Signature </p>
<div class="div4"> </div>
</div>
</div>
<div class="Threeform">
<form>
<fieldset>
<legend> User Confirmation </legend>
<div class="sign-container">
<div class="div1">User Name</div>
<div class='sign'> </div>
<div class="div1">System No</div>
<div class='sign'> </div>
</div>
<div class="policy-container">
<div class="div1">Received all the above mentioned facilities and understood international & FGC Cyber policy by
<div class='sign1'> </div></div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</form>
</div>
</body>
</html>
plz help me to rectify.
I am not able to connect from form.html page to addtodatabase.php .
Notice: Undefined index: firstname in C:\wamp64\www\Form\addtodatabase.php on line 12
You need to pass 2 parameters! $result = mysqli_query($connect, $query);

undefined index in php using post but it can echo the value using request on update.php

I have these two files and i am updating a table but on the update.php file i get error saying Notice: Undefined index: pname , $pcode...... $pname = $_POST["pname"]; here i am storing pname value in pname variable.but it shows error
<address>
<div class="control-group">
<label class="control-label">Product Name:</label>
<div class="controls">
<input id="pname" name="pname" type="text" value="<?php echo $PName; ?>"
class="input-xlarge">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">Product Code:</label>
<div class="controls">
<input id="code" name="pcode" type="text" value="<?php echo $PCode; ?>"
class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label">Product Price:</label>
<div class="controls">
<input id="price" name="pprice" type="text" value="<?php echo $PPrice; ?>"
class="input-xlarge">
</div>
</div>
<div class="control-group">
<label class="control-label">Availability:</label>
<div class="controls">
<select id="stock" name="stock" class="input-xlarge">
<option value="1" selected="selected">Available</option>
<option value="0">Not Available</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Product Description:</label>
<div class="controls">
<textarea rows="4" cols="50" name="description" > <?php echo $PDescription; ?> </textarea>
</div>
</div>
<div class="control-group">
Picture 1 :
<div class="controls">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<input type="file" name="pic1"
class="input-xlarge">
</div>
</div>
<div class="control-group">
Picture 2 :
<div class="controls">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<input type="file" name="pic2"
class="input-xlarge">
</div>
</div>
<div class="control-group">
Picture 3 :
<div class="controls">
<input type="hidden" name="MAX_FILE_SIZE" value="3000000" />
<input type="file" name="pic3"
class="input-xlarge">
</div>
</div>
<div class="control-group">
<div class="controls">
<input type='hidden' name='id' value="<?php echo $ID; ?>"><br/>
<input type="submit" value="UPDATE" class="btn-large" />
</div>
</div>
</form>
Do you check for form submit?
if (isset($_POST["pname"])) {
// do all your form processing here.
}
$pname= (isset($_POST["pname"]) ? $_POST["pname"] : "");
this will check if pname exists in $_POST and then sets it.
you receive that error because you dont have set $_POST["pname"]

Categories