Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong.
I have created a form and when I click on submit, the data in the form is not sent to my mysql database.
Here is my html code
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="page-head-line">Forms </h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">
BASIC FORM ELEMENTS
</div>
<div class="panel-body">
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name' type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description' type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date' type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
and here is my php
<?php
echo $POST;
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../includes/config.php");
if (isset($_POST['submit'])) {
echo $_POST['submit'];
$name = $_POST['name'];
$projectnum = $_POST['project_num'];
$projectname = $_POST['project_name'];
$easyvista = $_POST['easyvista'];
$agency = $_POST['agency'];
$description = $_POST['description'];
$startDate = $_POST['input-date'];
$sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
VALUES
('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";
if (!mysqli_query($conn, $sql))
{
die('Error: ' . mysqli_connect_error($conn));
}
echo "Entry is recored <br/>";
echo "Name:", $name, "<br/>";
echo "test..................<br/>", $name;
/*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/
//echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
mysqli_query($conn, $sql);
}
else {
echo "No data";
}
?>
Any help would be greatly appreciated.
Thanks
You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date" type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
And then, as #Fred -ii stated in his comment, the php script is wrong:
echo $POST;
That line is wrong, there is no variable with name $POST before that code.
Are you getting success message but database is not getting updated OR Getting Total Error...???
1) Check for double quotes and single quotes..
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
2) Also check for path... for
include("../includes/config.php");
Is it correct or not...?
3)
<label for="project_name">Project Name</label>
<input name="name' type="text"
SHOULD BE
<label for="project_name">Project Name</label>
<input name="project_name" type="text"
Related
I have a .php contact page that works and sends the information from the form to my email, but it also shows {value=""} in two places on my form.
Am I missing "
The code is as follows:
<?php
<form method="post" action="#contact" role="form">
<div class="form-inline">
<div class="col-md-9 form-group">
<label for="name">your name</label>
<span class="fieldSpan">
<input type="text"
input pattern=".{5,}"
required title="5 characters minimum"
name="name"
id="input-field-name"
class="form-control"
>
value="<?php echo $_POST['name']; ?>"
</div>
</div>
</div>
<div class="form-inline">
<div class="col-md-9 form-group">
<label for="email">your email address</label>
<span class="fieldSpan">
<input type="email"
name="email"
id="input-field-email"
input pattern=".{6,}"
required title="6 characters minimum"
class="form-control"
>
value="<?php echo $_POST['email'];?>"
</div>
</div>
</div>
Here your error
id="input-field-name"
class="form-control"
>
value="<?php echo $_POST['name']; ?>"
</div>
you put value=".... after the closing > of the input
Use code as follows.Input value always in tag
<form method="post" action="#contact" role="form">
<div class="form-inline">
<div class="col-md-9 form-group">
<label for="name">your name</label>
<span class="fieldSpan">
<input type="text"
input pattern=".{5,}"
required title="5 characters minimum"
name="name"
id="input-field-name"
class="form-control"
value="<?php echo $_POST['name']; ?>"
>
</div>
</div>
</div>
<div class="form-inline">
<div class="col-md-9 form-group">
<label for="email">your email address</label>
<span class="fieldSpan">
<input type="email"
name="email"
id="input-field-email"
input pattern=".{6,}"
required title="6 characters minimum"
class="form-control"
value="<?php echo $_POST['email'];?>"
>
</div>
</div>
</div>
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>
I have a problem.. I tried today a lot to make this working but it seems to be impossible for me.. so I decided to ask help here. So I have a form which needs to be added on database table when submit button is pressed.
This is php code I currently use.. I removed my tries btw:
<?php
$pdo = new PDO('mysql:host=;dbname=', '', '');
$sql = "SELECT * FROM games LIMIT 10";
foreach ($pdo->query($sql) as $row) {
?>
my HTML code (form):
<form class="form-group" method="POST" action="">
<div role="tabpanel" class="tab-pane active" id="home">
<div class="form-group" style="margin-top: 15px;">
<label for="exampleInputEmail1">Game Title</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="" name="gtitle" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">YouTube Link</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="" name="ytlink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link Source</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="ex: GLEAM, DLH, FAILMID, HRKGAME, INDIEGALA, OTHER, STEAM" name="slink" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Link to Free Steam Keys</label>
<input type="text" class="form-control" id="exampleInputPassword1" placeholder="KEY MUST GIVE +1 TO THE STEAM LIBRARY GAME COUNT" name="keysl" />
</div>
<label for="exampleInputPassword1">Steam App ID</label>
<div class="input-group" style="padding-bottom: 10px;">
<span class="input-group-addon" id="basic-addon3">http://store.steampowered.com/app/</span>
<input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3" placeholder="App ID" name="appid" />
</div>
<div class="form-group">
<label for="exampleInputPassword1">Categories</label>
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" /> 1
<h4><span class="label label-success">Keys Available</span></h4>
</label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" /> 2
<h4><span class="label label-danger">No Keys left</span></h4>
</label>
</div>
<button type="submit" class="btn btn-default" name="insert">Submit</button>
</div>
</div>
</form>
Thank those who help me.
Try this and in the radio button put value as '1' and '2' instead of 'option1' and 'option2'
if(isset($_POST['insert']))
{
$game_title=$_POST['gtitle'];
$youtube_link=$_POST['ytlink'];
$link_source=$_POST['slink'];
$link_steam_keys=$_POST['keysl'];
$app_id=$_POST['appid'];
$categories=$_POST['inlineRadioOptions'];
$query_ins="INSERT INTO tbl_game(game_title,youtube_link,link_source,link_steam_keys,app_id,categories) VALUES(:game_title,:youtube_link,:link_source,:link_steam_keys,:app_id,:categories)";
$stmt_query=$dbh->prepare($query_ins);
$games_ins=$stmt_query->execute(array(":game_title"=>$game_title,":youtube_link"=>$youtube_link,":link_source"=>$link_source,":link_steam_keys"=>$link_steam_keys,":app_id"=>$app_id,":categories"=>$categories));
if(!$games_ins)
{
$error=$stmt_query->errorInfo();
echo $error['2'];
}
}
You need to check the POST variables after submitting in your PHP code. If the form is submitted, take the post values and just run an INSERT query.
See $_POST
I am recently getting into php and am running it locally on Xampp. I have created the following simple form followed by a few lines of php. It seems that no data is being passed through from the html form to the php page.
<form method="post" action="emailform.php" enctype="text/plain" class="form-horizontal">
<div class="row input">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="form-group">
<input type="text" name="subject" id="subject" class="form-control" placeholder="subject">
</div>
</div>
</div>
<div class="row input">
<div class="col-md-1"></div>
<div class="col-md-4">
<div class="form-group">
<input type="text" name="name" id="name" class="form-control" placeholder="full name">
</div>
<div class="form-group">
<input type="email" name="subject" id="email" class="form-control" placeholder="email">
</div>
</div>
<div class="col-md-1"></div>
<div class="col-md-5 textarea">
<textarea class="form-control" name="message" id="message" rows="4" placeholder="message"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<button type="submit" class="btn" id="submit">Send</button>
</div>
</div>
</form>
This is the simple php code I am using to test:
<?php
$subject = 'No subject was set';
if (isset($_POST['subject'])) {
$subject = ($_POST['subject']);
}
echo "This is the subject:$subject";
?>
I appreciate any help as I have been struggling with this simple code for the past week now.
Two subject names!
<input type="email" name="subject" id="email" class="form-control" placeholder="email">
^
and
<input type="text" name="subject" id="subject" class="form-control" placeholder="subject">
^
Also remove enctype="text/plain" from the form
It's because PHP doesn't handle it
I've made a contact form for my website, included the html and the php, it does send an email which does show "name: email: message:" but after that it's empty, so it doesn't show what you type in the form, please help!
Here is the html:
<form action="thankyou.php" method="post">
<div class="col-md-5" style="margin-top:15px;">
<div class="form-group">
<label for="contact-name" class="col-sm-2 control-label">Naam</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="contact-name" placeholder="First & Last name" />
</div>
</div>
<div class="form-group">
<label for="contact-email" class="col-sm-2 control-label" style="margin-top:15px;">Email</label>
<div class="col-sm-10" style="margin-top:15px;">
<input type="text" class="form-control" id="contact-name" placeholder="example#domain.com" />
</div>
</div>
<div class="form-group">
<label for="contact-message" class="col-sm-2 control-label" style="margin-top:15px;">Message</label>
<div class="col-sm-10" style="margin-top:15px;">
<textarea class="form-control" rows="4"></textarea>
</div>
</div>
<button style="btn-align:center; margin-left:88px; margin-top:15px;" type="submit" class="btn btn-primary">Verstuur</button>
</div>
</div>
</div>
</form>
Here is the php:
<?
$name = $_POST['contact-name'];
$email = $_POST['contact-email'];
$message = $_POST['contact-message'];
$email_message = "
Name:".$name."
Email:".$email."
Message:".$message."
";
mail ( "email#example.com" , "New inquiry", $email_message);
?>
Your form fields are all missing the name attribute. Without it that data is not sent.
<input type="text" class="form-control" name="contact-name" id="contact-name" placeholder="First & Last name" />
^^^^
This is missing for all form fields