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>
Yes! that's the exact doubt I have. I was given an assignment of
Create a form using smarty functions
(fields should be First Name, Last Name, Address, Email, Gender,
Qualifications, Phone number, etc.)
and I don't have any idea what they are talking about. So I want to ask that is there any function() which is used for making form elements or any other possibilities?I tried searching on google but didn't get any positive result.
PHP Code
<?php
include_once "../prepengine-header.php";
$lets = $_POST['user_lang'][1];
$var = $_POST['user_lang'][0];
$var .= $lets;
$formdata = "";
if (isset($data['submit'])) {
$formdata .= $data['user_firstname']."\n" ;
$formdata .= $data['user_lastname']."\n" ;
$formdata .= $data['user_address']."\n" ;
$formdata .= $data['user_qual']."\n" ;
$formdata .= $data['user_gender']."\n" ;
$formdata .= $var."\n" ;
$formdata .= $data['user_email']."\n" ;
$formdata .= $data['user_num']."\n" ;
$formdata .= $data['user_select']."\n" ;
}
$theme->assign('data',$data);
$theme->assign('formdata',$formdata);
echo($theme->fetch('smartart/screen5-a (1).tpl'));
?>
Smarty code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form class="form-horizontal" name="registration_form" id="registration_form" method="post" action="#">
<div class="form-group">
<label class="control-label col-lg-2" for="firstname">First Name: <sup style="color: #FF0000;">*</sup></label>
<div class="col-lg-10">
<input type="text" name="firstname" id="firstname" placeholder="Enter firstname" class="form-control" required="required" />
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="lastname">Last Name: <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<input type="text" name="lastname" id="lastname" placeholder="lastname" class="form-control" required="required" />
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="address">Address <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<textarea id="address" name="address" class="form-control" placeholder="Provide Address" required="required"></textarea>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="gender">Gender <span style="color: #FF0000;">*</span></label>
<div class="col-lg-10">
<{html_radios name='gender' values=$cust_id output=$cust_gender selected=$custom_id separator='<br />'}>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="user_lang">Languages</label>
<div class="col-lg-10">
<{html_checkboxes name='user_lang' values=$cust_ids output=$cust_names selected=$customer_id separator='<br/>'}>
</div>
</div>
<div class="form-group row">
<label class="control-label col-lg-2" for="user_country">Country</label>
<div class="col-lg-10">
<{html_options name='select' options=$myOptions class="form-control"}>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" name="submit" id="submit_button" class="btn btn-default" value="Submit">
</div>
</div>
</form>
</div>
</body>
</html>
Can anyone help with a php error. My contact form comes back with
404 - File or directory not found
This is my form
<form action="contact.php" class="contact-form" accept-charset="UTF-8" role="form">
<div class="form-group col-md-6">
<label class="sr-only" for="exampleInputEmail1">Your Name: *</label>
<input required type="text" class="form-control" id="inputName" placeholder="Your Name: *">
</div>
<div class="form-group col-md-6">
<label class="sr-only" for="exampleInputEmail1">Email: *</label>
<input required type="email" class="form-control" id="inputEmail1" placeholder="Email: *">
</div>
<div class="clearfix"></div>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail1">Subject:</label>
<input type="text" class="form-control" id="inputName" placeholder="Subject:">
</div>
<div class="form-group">
<textarea required class="form-control" rows="5" placeholder="Message: *"></textarea>
</div>
<button type="submit" class="btn btn-lg btn-primary">Submit</button>
</form>
and this is my PHP
<?php
$mail = "jade#------.CO.UK";
if($_POST['message']) {
$message = "<h2>Hello here is a message from ".$_SERVER['SERVER_NAME']."</h2><hr>
<p><strong>Name:</strong> ".$_POST['name']."</p>
<p><strong>Email:</strong> ".$_POST['email']."</p>
<p><strong>Message:</strong> ".$_POST['message']."</p>";
$subject="Premium template message: ".$_POST['subject'];
mail($mail, $subject, $message, "Content-type: text/html; charset=utf-8 \r\n");
echo 'AAAAAAAAAAAAAAA';
}
?>
I'm quite new to this and its driving me crazy.
Thanks
Your form doesn't have a method. Since you are posting data, add the POST method in html like this
<form action="contact.php" method="POST" class="contact-form" accept-charset="UTF-8" role="form">
And hope that contact.php is in the same directory as well.
Check the proper relative contact.php file location. If you are submiting the form to the same file you are in then just remove action="contact.php". Also you need to add method. Here's how it should be. Mark action and method in the below code.
<form action="" method="post" class="contact-form" accept-charset="UTF-8" role="form">
<div class="form-group col-md-6">
<label class="sr-only" for="exampleInputEmail1">Your Name: *</label>
<input required type="text" class="form-control" id="inputName" placeholder="Your Name: *">
</div>
<div class="form-group col-md-6">
<label class="sr-only" for="exampleInputEmail1">Email: *</label>
<input required type="email" class="form-control" id="inputEmail1" placeholder="Email: *">
</div>
<div class="clearfix"></div>
<div class="form-group">
<label class="sr-only" for="exampleInputEmail1">Subject:</label>
<input type="text" class="form-control" id="inputName" placeholder="Subject:">
</div>
<div class="form-group">
<textarea required class="form-control" rows="5" placeholder="Message: *"></textarea>
</div>
<button type="submit" class="btn btn-lg btn-primary">Submit</button>
</form>
Final Edit:
Thank you everyone for the help. I have been trying to write all the code related to connection in index.php rather than submit.php. It is resolved now.
Edit:
I have updated the code based on your feedback.
I am able to get the values to the database now but the thing is it is showing only empty results. here is the updated code.
<form action="submit.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="name" class ="col-lg-2 control-label" > Name</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="name" name="name" placeholder="Enter your Name" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="email" class ="col-lg-2 control-label" > Email</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="email" name="email" placeholder="Enter your email address" required>
</div>
</div>
</div> <div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="subject" class ="col-lg-2 control-label" > Subject</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="subject" name="subject" placeholder="Your Subject" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal">
<div class="form-group">
<label for="message" class ="col-lg-2 control-label" > Message</label>
<div class="col-lg-7">
<textarea name="message" class="form-control" id ="message" cols="20" rows="3" placeholder="Your Message"></textarea>
</div>
</div> <!-- end form -->
<div class="col-lg-1">
</div>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
PHP Code:
<?php
if (isset($_POST)) {
$conn = mysqli_connect($servername, $username, $password, $db_name);// Establishing Connection with Server
mysqli_set_charset($conn, 'utf8');
if (!$conn) {
die("Database connection failed: " . mysqli_error($conn));
}
else
echo "connected successfully";
//Escaping string, not 100% safe, also consider validating rules and sanitization
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$subject = mysqli_real_escape_string($conn, $_POST['subject']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
$result = mysqli_query($conn, "INSERT INTO contact (user, email, subject, message) VALUES ('$name', '$email', '$subject', '$message')");
}
?>
Here is the snapshot of the database
I have a form made using HTML. I want to store the results when i submit the form in the database. The connection was successful but the data is not being stored in the database.
Basically what submit.php does is just sent the text "Successfully submited the form".
Here's my code:
<form action="submit.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="name" class ="col-lg-2 control-label" > Name</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="name" placeholder="Enter your Name" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="email" class ="col-lg-2 control-label" > Email</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="email" placeholder="Enter your email address" required>
</div>
</div>
</div> <div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="subject" class ="col-lg-2 control-label" > Subject</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="subject" placeholder="Your Subject" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal">
<div class="form-group">
<label for="message" class ="col-lg-2 control-label" > Message</label>
<div class="col-lg-7">
<textarea name="message" class="form-control" id ="message" cols="20" rows="3" placeholder="Your Message"></textarea>
</div>
</div> <!-- end form -->
<div class="col-lg-1">
</div>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
PHP code:
$conn = mysqli_connect($servername, $username, $password, $db_name);// Establishing Connection with Server
mysqli_set_charset($conn, 'utf8');
if (!$conn) {
die("Database connection failed: " . mysqli_error($conn));
}
else
echo "connected successfully";
if (isset($_POST['submit'])) {
//Escaping string, not 100% safe, also consider validating rules and sanitization
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$subject = mysqli_real_escape_string($conn, $_POST['subject']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
$result = mysqli_query($conn, "INSERT INTO contact (user, email, subject, message) VALUES ('$name', '$email', '$subject', '$message');");
if ($result) {
$message="successfully sent the query!!";
}
else
{$message="try again!!";}
}
?>
None of your input fields have a name="" attribute, including the button. So none of these fields will be sent in the $_POST array.
Add a name="" attribute like this to all the fields you want sent to PHP
<form action="submit.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="name" class ="col-lg-2 control-label" > Name</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="name" name="name" placeholder="Enter your Name" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="email" class ="col-lg-2 control-label" > Email</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="email" name="email" placeholder="Enter your email address" required>
</div>
</div>
</div>
<div class="col-lg-1"></div>
<div class="form-horizontal" >
<div class="form-group">
<label for="subject" class ="col-lg-2 control-label" > Subject</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="subject" name="subject" placeholder="Your Subject" required>
</div>
</div>
</div>
<div class="col-lg-1"></div>
<div class="form-horizontal">
<div class="form-group">
<label for="message" class ="col-lg-2 control-label" > Message</label>
<div class="col-lg-7">
<textarea name="message" class="form-control" id ="message" name="message" cols="20" rows="3" placeholder="Your Message"></textarea>
</div>
</div> <!-- end form -->
<div class="col-lg-1"></div>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-2">
<button type="submit" class="btn name="submit" btn-primary">Submit</button>
</div>
</div>
</form>
Also in your code in submit.php change this so you see an actual error message if one occurs.
if ($result) {
$message="successfully sent the query!!";
} else {
$message="Insert failed : " . mysqli_error($conn);
}
echo $message;
Although this does assume you are actually showing the $message value somewhere in your code that you have not shown us.
You have to add name attribute to your button element so that if (isset($_POST['submit'])) will be true.
Please change
<button type="submit" class="btn btn-primary">Submit</button>
to
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
or
<input type="submit" name="submit" value="Submit" class="btn btn-primary" />
First of all you must need to provide name attribute for each input tags and button tags for a better approach :
<form action="submit.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="name" class ="col-lg-2 control-label" > Name</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="name" name ="name" placeholder="Enter your Name" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="email" class ="col-lg-2 control-label" > Email</label>
<div class="col-lg-7">
<input type="text" class="form-control" name ="email" id ="email" placeholder="Enter your email address" required>
</div>
</div>
</div> <div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="subject" class ="col-lg-2 control-label" > Subject</label>
<div class="col-lg-7">
<input type="text" class="form-control" name ="subject" id ="subject" placeholder="Your Subject" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal">
<div class="form-group">
<label for="message" class ="col-lg-2 control-label" > Message</label>
<div class="col-lg-7">
<textarea name="message" class="form-control" name ="message" id ="message" cols="20" rows="3" placeholder="Your Message"></textarea>
</div>
</div> <!-- end form -->
<div class="col-lg-1">
</div>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-2">
<button type="submit" name ="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
Php Code for Insert data in DB :
$result = mysqli_query($conn, "INSERT INTO contact (user, email, subject, message) VALUES ('".$name."', '".$email."', '".$subject."', '".$message."')");
Try this code :-
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$conn = mysqli_connect($servername, $username, $password, $db_name);// Establishing Connection with Server
mysqli_set_charset($conn, 'utf8');
if (!$conn) {
die("Database connection failed: " . mysqli_error($conn));
}
else
echo "connected successfully";
//Escaping string, not 100% safe, also consider validating rules and sanitization
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$subject = mysqli_real_escape_string($conn, $_POST['subject']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
$result = mysqli_query($conn, "INSERT INTO contact (user, email, subject, message) VALUES ('$name', '$email', '$subject', '$message')");
echo "INSERT INTO contact (user, email, subject, message) VALUES ('$name', '$email', '$subject', '$message')";//die;
if ($result) {
$message="successfully sent the query!!";
}
else
{$message="try again!!";}
}
?>
<form action="index.php" method="post" class="form-horizontal">
<div class="form-group">
<label for="name" class ="col-lg-2 control-label" > Name</label>
<div class="col-lg-7">
<input type="text" class="form-control" name ="name" id ="name" placeholder="Enter your Name" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="email" class ="col-lg-2 control-label" > Email</label>
<div class="col-lg-7">
<input type="text" class="form-control" id ="email" name="email" placeholder="Enter your email address" required>
</div>
</div>
</div> <div class="col-lg-1">
</div>
<div class="form-horizontal" >
<div class="form-group">
<label for="subject" class ="col-lg-2 control-label" > Subject</label>
<div class="col-lg-7">
<input type="text" name="subject" class="form-control" id ="subject" placeholder="Your Subject" required>
</div>
</div>
</div>
<div class="col-lg-1">
</div>
<div class="form-horizontal">
<div class="form-group">
<label for="message" class ="col-lg-2 control-label" > Message</label>
<div class="col-lg-7">
<textarea name="message" class="form-control" id ="message" cols="20" rows="3" placeholder="Your Message"></textarea>
</div>
</div> <!-- end form -->
<div class="col-lg-1">
</div>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-2">
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</div>
</div>
</form>
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