Having an issue with PHP $_POST - php

I am trying to tie my html form to a PHP mailer and for some reason the form inputs are not storing in my variables. I have tried searching all over and I cannot see what I am doing wrong. Any help would be greatly appreciated.
Form handler:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$date = trim($_POST["date"]);
$guests = trim($_POST["guests"]);
$description = trim($_POST["description"]);
}
Form:
<form role="form" class="text-center" method="POST" enctype="text/plain" action="index.php">
<div class="form-group">
<label for="name">Nombre</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Correo Electrónico</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="date">Fecha del Evento</label>
<input type="date" id="date" class="form-control" name="date">
</div>
<div class="form-group">
<label for="guests">Número de Huéspedes</label>
<select class="form-control" id="guests" name="guests">
<option>1 - 2</option>
<option>3 - 4</option>
<option>5 - 6</option>
<option>7 - 8</option>
</select>
</div>
<div class="form-group">
<label for="description">Descripción de Evento</label>
<textarea class="form-control" id="description" rows="3" name="description"></textarea>
</div>
<div style="display: none;">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="address">
</div>
<input type="submit" class="btn btn-default" value="Enviar">
</form>

For PHP text/plain is not a valid value for enctype in <form>
Take a look here

Related

How to collect form data (text arrays) after submitting using POST method

how to use POST method with arrays in PHP? I have never learnt PHP, so don't have a clue how to make it. I have a form:
<form method="post" action="email-script.php" enctype="multipart/form-data" id="emailForm">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" >
<div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
</div>
<div class="form-group">
<input type="text" name="surname" id="surname" class="form-control" placeholder="Surame" >
<div id="nameError" style="color: red;font-size: 14px;display: none">nameError</div>
</div>
<div class="form-group">
<input type="text" name="phone" id="phone" class="form-control" placeholder="Phone" >
<div id="subjectError" style="color: red;font-size: 14px;display: none">subjectError</div>
</div>
<div class="form-group">
<label>First Level Category</label><br />
<select id="first_level" name="first_level[]" multiple class="form-control">
<?php
foreach($result as $row)
{
echo '<option value="'.$row["first_level_category_id"].'">'.$row["first_level_category_name"].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Second Level Category</label><br />
<select id="second_level" name="second_level[]" multiple class="form-control">
</select>
</div>
<div class="form-group">
<label>Third Level Category</label><br />
<select id="third_level" name="third_level[]" multiple class="form-control">
</select>
</div>
<div class="form-group">
<input type="file" name="attachment" id="attachment" class="form-control">
<div id="attachmentError" style="color: red;font-size: 14px;display: none">attachmentError</div>
</div>
<div class="submit">
<center><input type="submit" name="submit" onclick="return validateEmailSendForm();" class="btn btn-success" value="SUBMIT"></center>
</div>
</form>
Then I am collecting submited data from the form:
if(isset($_POST['submit'])){
// Get the submitted form data
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$date = $date = date('Y-m-d H:i:s');
$uploadStatus = 1;
I've found out how to collect data with text values, like name, phone, etc. But I don't know how to collect data with text arrays like first_level[], second_level[] and third_level[]. I would greatly appreciate it if you kindly give me some hints.

can't connect a laravel api.php rout from an html form

I am trying to post a form from a HTML file to a live database using laravel api.php route. But it's yielding the following error :
my api.php looks like :
<?PHP
use Illuminate\Http\Request;
use App\Http\Controllers\User\PageController;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('summitRegistration',[PageController::class,'summitRegistration']);
My HTML code :
<form action="https://www.aspireelearning.com/summitRegistration" method="POST">
<div class="col-12 col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="full_name" id="full_name"
placeholder="Your Full Name">
<input type="text" class="form-control" name="phone" id="phone"
placeholder="Phone Number">
<input type="text" class="form-control" name="profession" id="profession"
placeholder="Profession">
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<input type="email" class="form-control" name="email" id="email"
placeholder="Email Address" required>
<input type="text" class="form-control" name="organization" id="organization"
placeholder="Organization/Institute">
<select class="form-control country-search" name="country" id="country">
<option value="">Your Country</option>
<option value="">USA</option>
<option value="">UK</option>
</select>
</div>
</div>
<div class="col-12 text-center">
<button type="submit" class="btn btn-danger">
CONFIRM
</button>
</div>
</form>
i have update action and also added #csrf token now i hope you will get your out put .
<form action="https://www.aspireelearning.com/api/summitRegistration" method="POST">
//#csrf
<div class="col-12 col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="full_name" id="full_name"
placeholder="Your Full Name">
<input type="text" class="form-control" name="phone" id="phone"
placeholder="Phone Number">
<input type="text" class="form-control" name="profession" id="profession"
placeholder="Profession">
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<input type="email" class="form-control" name="email" id="email"
placeholder="Email Address" required>
<input type="text" class="form-control" name="organization" id="organization"
placeholder="Organization/Institute">
<select class="form-control country-search" name="country" id="country">
<option value="">Your Country</option>
<option value="">USA</option>
<option value="">UK</option>
</select>
</div>
</div>
<div class="col-12 text-center">
<button type="submit" class="btn btn-danger">
CONFIRM
</button>
</div>
</form>
You have to add api as prefix https://www.aspireelearning.com/api/summitRegistration

Issue populating textarea with db data

So, like the title said, i'm having an issue while i'm populating a text area that is being used on HTML form, because it is not getting any content in it.
this is the form with the php while.
<?php
while ($row = mysqli_fetch_array($query))
{ echo '
<form action="insert/insertReport.php" id="newReport" method="post">
<div class="form-group">
<label for="clientRep">Cliente</label>
<br>
<input type="text" name="client" class="form-control" id="client" value="'.$row['client'].'">
</div>
<div class="form-group">
<label for="titleRep">Título do Relatório</label>
<br>
<input type="text" name="title" class="form-control" id="title" value="'.$row['title'].'">
</div>
<div class="form-group">
<label for="namefat">Data</label>
<br>
<input type="text" name="date" class="form-control" id="date" value="'.$row['date'].'">
</div>
<div class="form-group">
<label for="localRep">Local</label>
<br>
<input type="text" name="local" class="form-control" id="local" value="'.$row['local'].'">
</div>
<div class="form-group">
<label for="reportRep">Relatório</label>
<br>
<textarea rows="12" name="report" class="form-control" id="report" form="newReport" value="'.$row['report'].'"></textarea>
</div>
<input type="hidden" name="id" class="form-control" id="id" value="'.$row['id'].'">';
}?>
And this is the php query.
$sql = 'SELECT * FROM reports'
Does anyone know what's wrong with it?
Text area does not accept a value attribute. You place the contents between the textarea tags:
<textarea rows="12" name="report" class="form-control" id="report" form="newReport">'.$row['report'].'</textarea>

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

how to save data in database using submit button?

I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook.
So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks for your help!
<form
action="employee_list.php" method="post"
<input type="submit"
name="passport" id="passport" action="uraction" method="post" enctype="multipart/form-data"
<label for="upload" >Select Employee Passport</label><input type="file" id="upload" name="upload" accept="image/*">
<p/>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="name">Employee Full Name</label>
<input type="text" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
</div>
<div class="col-md-6">
<label for="gender">Gender</label>
<select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
</select>
</div>
<div class="col-md-6">
<label for="maritalstatus">Marital Status</label>
<select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
</select>
</div>
<div class="col-md-6">
<label for="department">Department</label>
<input type="text" class="form-control" id="Position" aria-describedby="nameHelp" placeholder="Enter The Department">
</div>
<div class="col-md-6">
<label for="salary">Salary</label>
<input type="number" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="">
</div>
<div class="col-md-6">
<label for="certificate"> Highest Certificate Acquired</label>
<input type="text" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="Enter Highest Certificate Acquired">
</div>
</div>
</div>
<div class="form-group">
<label for="Email">Email Address</label>
<input type="emai" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="address">House Address</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="phonenumber">Phone Number</label>
<input type="number" class="form-control" id="phonenumber">
</div>
</form>
</div>
<!-- /.content-wrapper -->
PHP script:
<?php
if(isset($_POST['submit'])) {
$SQL = "INSERT INTO tbl_employee (name, gender,
marital_status,department,salary,certificate, email,address,phone_number)
VALUES ('$_POST[name]', '$_POST[gender]',
'$_POST[marital_status],'$_POST[department]','$_POST[salary]‌​
','$_POST[certificat‌​
e]','$_POST[email]',‌​'$_POST[address]','$‌​_POST[phone_numer]')‌​"; $result =
mysql_query($SQL);
}
?>
<html>
<head>
<title>Check</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php include('dbconnect.php');
if($_POST['submit']){
$fullname = $_POST['exampleInputName'];
$gender = $_POST['gender'];
$status = $_POST['status'];
$position = $_POST['position'];
$salary = $_POST['salary'];
$certificate = $_POST['certificate'];
$exampleInputEmail1 = $_POST['exampleInputEmail1'];
$phonenumber = $_POST['phonenumber'];
}
$data = "INSERT INTO test (`id`, `fullname`, `gender`, `matrial_status`, `department`, `salary`, `certificate`, `email`, `address`)VALUES ('', '$fullname', '$gender', '$status', '$position', '$salary', '$certificate', '$exampleInputEmail1', '$phonenumber')";
mysqli_query($con,$data);
?>
<form action="checkbox.php" method="POST" >
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="name">Employee Full Name</label>
<input type="text" class="form-control" id="exampleInputName" name="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
</div>
<div class="col-md-6">
<label for="gender">Gender</label>
<select type="text" name="gender" class="form-control" id="gender" aria-describedby="nameHelp">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div class="col-md-6">
<label for="maritalstatus">Marital Status</label>
<select type="text" name="status" class="form-control" id="status" aria-describedby="nameHelp">
<option value="Married">Married</option>
<option value="Unmarried">Unmarried</option>
</select>
</div>
<div class="col-md-6">
<label for="department">Department</label>
<input type="text" class="form-control" name="position" id="position" aria-describedby="nameHelp" placeholder="Enter The Department">
</div>
<div class="col-md-6">
<label for="salary">Salary</label>
<input type="number" class="form-control" name="salary" id="salary" aria-describedby="nameHelp" placeholder="">
</div>
<div class="col-md-6">
<label for="certificate"> Highest Certificate Acquired</label>
<input type="text" class="form-control" id="certificate" name="certificate" aria-describedby="nameHelp" placeholder="Enter Highest Certificate Acquired">
</div>
</div>
</div>
<div class="form-group">
<label for="Email">Email Address</label>
<input type="emai" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="address">House Address</label>
<input type="text" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
</div>
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label for="phonenumber">Phone Number</label>
<input type="text" class="form-control" name="phonenumber" id="phonenumber">
</div>
</div>
</div>
<input type="submit" name="submit" id="passport">
</form>
</body>

Categories