My Google recaptcha verification is not working - php

I am using this code to work recaptcha services. But it tells me you are a bot.
I tried php server side integration but it does not work.
Here is html
<form id="contact-form" name="contact-form" action="submithr.php" method="POST">
<!--Grid row-->
<div class="row">
<div class="col-md-8">
<div class="md-form mb-0">
<label for="subject" class="">Subject</label>
<input type="text" id="subject" name="subject" class="form-control" required>
</div>
</div>
<!--Grid column-->
<div class="col-md-4">
<div class="md-form mb-0">
<label for="category" class="">Select Category</label>
<select type="text" id="category" name="category" class="form-control">
<option value="1">Suggestion</option>
<option value="2">Claim</option>
<option value="3">Help</option>
</select>
</div>
</div>
<!--Grid column-->
</div>
<!--Grid row-->
<!--Grid row-->
<div class="row">
<!--Grid column-->
<div class="col-md-12">
<div class="md-form">
<label for="message">Your message</label>
<textarea type="text" id="message" name="message" rows="2" class="form-control md-textarea" required></textarea>
</div>
</div>
</div>
<!--Grid row-->
<br>
<div class="g-recaptcha" data-sitekey="---My site key---"></div>
<br>
<div class="text-center text-md-left">
<a class="btn btn-primary" onclick="document.getElementById('contact-form').submit();">Send</a>
</div>
</form>
And here is php code
<?php
$subject = $_POST['subject'];
$category = $_POST['category'];
$message = $_POST['message'];
$secretKey = "---My Secret Key---";
$responseKey = $_POST['g-recaptcha-response'];
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$response = file_get_contents($url);
$response = json_decode($response);
if ($response->success) {
echo "<script> alert('Thank you For Posting Suggestion')</script>";
}
else{
echo "<script> alert('It looks like you are bot.Try Again')</script>";
}
?>
If check box is checked correctly it should alert me that i checked it correctly But even if i check it correctly it always alert me you are a bot.

Set this file in your html page containinig the form
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Then set the google div box before your submission button
<div class="g-recaptcha" data-sitekey="Your recaptcha site key here"></div>
here is the php code
<?php
$subject = $_POST['subject'];
$category = $_POST['category'];
$message = $_POST['message'];
// Ensure that recaptchabox is not empty
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
$secretKey = 'Your_reCAPTCHA_Secret_Key_goes here';
// send request and Verify the reCAPTCHA via g_recaptcha_response post parameter.
$verifyRequest = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']);
$result = json_decode($verifyRequest);
// Check if captcha enterd is valid
if($result->success){
// send your form data and update database
echo "<script> alert('Thank you For Posting Suggestion')</script>";
}else{
echo "<script> alert('Faizan You are bot. hahaha....')</script>";
}
}else{
echo "Recaptcha box cannot be empty";
}
?>

Related

HTML/PHP Email forms not functioning as wanted

I am doing a contact us form into my website, and i am now stuck.
Here's the PHP code:
#Receive user input
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$palvelu = $_POST['palvelu'];
#Filter user input
function filter_email_header($form_field) {
return preg_replace('/[nr|!/<>^$%*&]+/','',$form_field);
}
$Email = filter_email_header($Email);
#Send email
$headers = "From: $Email\r\n";
$sent = mail('user#example.com', 'Yhteydenotto Pyyntö: ', $Message, $headers);
#Thank user or notify them of a problem
if ($sent) {
?><html>
<head>
<title>Kiitos yhteydenotosta!</title>
</head>
<body>
<h1>Kiitos yhteydenotosta!</h1>
<p>Olemme sinuun yhteydessä mahdollisimman nopeasti!</p>
</body>
</html>
<?php
} else {
?><html>
<head>
<title>Jokin meni vikaan!</title>
</head>
<body>
<h1>Jokin meni vikaan!</h1>
<p>Emme pystyneet lähettämään viestiä?</p>
</body>
</html>
<?php
}
?>
And here's the html code of the form:
<div class="col-lg-5 d-flex align-items-stretch">
<div class="bg-white">
<div class="w-100 heading-title bg-primary text-center">
<h2 class="mb-0">Ota meihin yhteyttä!</h2>
</div>
<form action="email.php" method="post" class="appointment bg-white p-4 p-md-5">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon"><span class="fa fa-chevron-down"></span></div>
<select name="palvelu" id="" class="form-control">
<option value="">Valitse palvelu</option>
<option value="">Sammaleen poisto</option>
<option value="">Katon pinnoitus</option>
<option value="">Tiilikaton huolto</option>
<option value="">Vuosihuolto</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" id="Name" name="Name" placeholder="Nimi" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="Email" id="Email" name="Email" placeholder="Sähköposti" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="input-wrap">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="input-wrap">
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea id="Message" name="Message" class="form-control" placeholder="Viesti" rows="6" maxlength="3000"></textarea>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="submit" value="Lähetä viesti" class="btn btn-primary py-3 px-4">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
So that's in finnish but i have this list where you can select what job you want to discuss "palvelut" and then the basic form. What it should do is to send an email with "who sent it" "the job they want" and the basic form stuff "name" "email" and the "message". But now it only seems to send an blank email with only the "yhteydenotto pyyntö" it means like "a new question". Could someone help me? What am i doing wrong...
Solution Here!!!
* Your filter_email_header is contain Problem so we use Default FILTER_SANITIZE_EMAIL filter.
Remove code
#Filter user input
function filter_email_header($form_field) {
return preg_replace('/[nr|!/<>^$%*&]+/','',$form_field);
}
$Email = filter_email_header($Email);
Replace the Fix
// Remove all illegal characters from email
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
*Your Form select option not present value so whatare the value select empty value to shown email form
<select name="palvelu" id="palvelu" class="form-control">
<option value="Valitse palvelu">Valitse palvelu</option>
<option value="Sammaleen poisto">Sammaleen poisto</option>
<option value="Katon pinnoitus">Katon pinnoitus</option>
<option value="Tiilikaton huolto">Tiilikaton huolto</option>
<option value="Vuosihuolto">Vuosihuolto</option>
</select>

Contact form not working in wordpress

I am trying to create a contact form in php. But the problem I am facing is that when ever I try to submit the form it shows 404 exception rather than the actual file which has the contact form. The theme is custom made. I have added my code below
<?php
if(isset($_POST)) {
if(trim($_POST["name"]) === "") {
$nameError = "Please enter your name.";
$hasError = true;
} else {
$name = trim($_POST["name"]);
}
if(trim($_POST["email"]) === "") {
$emailError = "Please enter your email address.";
$hasError = true;
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*#[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST["email"]))) {
$emailError = "You entered an invalid email address.";
$hasError = true;
} else {
$email = trim($_POST["email"]);
}
if(trim($_POST["phone"]) === "") {
$phoneError = "Please enter your phone address.";
$hasError = true;
} else {
$phone = trim($_POST["phone"]);
}
if(trim($_POST["comments"]) ==="") {
$commentError = "Please enter a message.";
$hasError = true;
} else {
if(function_exists("stripslashes")) {
$comments = stripslashes(trim($_POST["comments"]));
} else {
$comments = trim($_POST["comments"]);
}
}
if(!isset($hasError)) {
$emailTo = get_option("tz_email");
if (!isset($emailTo) || ($emailTo == "") ){
$emailTo = get_option("admin_email");
}
$subject = "[PHP Snippets] From ".$name;
$body = "Name: $name \n\nEmail: $email \n\nPhone:$phone\n\nComments: $comments";
$headers = "From: ".$name." <".$emailTo.">" . "\r\n" . "Reply-To: " . $email;
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
<?php get_header(); ?>
<div class="row" style="margin-top:150px;">
<div class="bg-container"></div>
<div class="col-md-4">
<div class="card contact-form-card">
<form action="<?php esc_url(the_permalink());?>" method="post">
<fieldset>
<legend>Give us your details</legend>
<div class="form-group label-floating">
<label class="control-label" for="user-name">Enter your full name</label>
<input class="form-control" id="user-name" name="name" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label" for="user-email">Enter your email id</label>
<input class="form-control" id="user-email" name="email" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label" for="user-phone">Enter your phone number</label>
<input class="form-control" id="user-phone" name="phone" type="text">
</div>
<div class="form-group label-floating">
<label class="control-label" for="commenets">Comments</label>
<textarea class="form-control" id="commenets" name="comments" type="text"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-primary btn-raised col-xs-12">Submit</button>
</fieldset>
</form>
</div>
</div>
<div class="col-md-8">
<h1 class="text-center">We are currently maintaining over 1000 properties in north Bangalore</h1>
<div class="owl-carousel">
<div class="item card">
<p class="statement">"Poorna is an immaculate real estate consulting professional, and possess several unique skills up his sleeves like property consulting report writing that are rare to find in a professional framework."</p>
<p class="by">Shariq Saleem, Director, Armchair Solutions India</p>
</div>
<div class="item card">
<p class="statement">"Square Capital Assets understands your needs clearly and they are very easy to work with. Once they taken over managing my property, it was a smooth ride"</p>
<p class="by">Manoj</p>
</div>
</div>
</div>
</div>
<div class="row" style="margin-top:15px;">
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/sign_the_agreement.png";?> alt="Sign the agreement">
<h5>Sign with us</h5>
</div>
</div>
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/choose_your_tenants.png";?> alt="Choose your tenants">
<h5>We will find reliable tenants.</h5>
</div>
</div>
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/collect_security_deposit.png";?> alt="Collect Security Deposit">
<h5>Rental Agreement</h5>
</div>
</div>
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/rent_assured.png";?> alt="Rent Assured">
<h5>Collecting rent and keeping your home safe</h5>
</div>
</div>
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/repairs_under_2000.png";?> alt="Repairs Under Rs.2,000">
<h5>Regular check up and maintenance</h5>
</div>
</div>
<div class="col-sm-2">
<div class="col-xs-12 feature-tile text-center">
<img src=<?php echo get_template_directory_uri()."/img/property_tax.png";?> alt="Property Taxes?">
<h5>Managing taxes and bills</h5>
</div>
</div>
</div>
<?php get_footer(); ?>
Just change the fields name like below
<input class="form-control" id="user-name" name="Fname" type="text">
<input class="form-control" id="user-email" name="Femail" type="text">
You will not get 404 error
:)
Naming a field in the form "name" caused that problem.
I renamed it to customer name and it started working

PHP mailer form data verification isn't working

NOTE: the mail function itself works fine, I have a hosted site with mail configured professionally. Mail is sent via this script, but my simple empty field handler never catches empty fields. I'm sure this is something super obvious, but I'm very new to php and the logic of my script seems sound. The code follows:
edit: I've left the form call within the php script in case someone finds issue with the bootstrap form itself. The redirect is temporary until I can get better form error handling going.
<body>
<!-- jQuery and bootstrap -->
<script src="https://code.jquery.com/jquery.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/counter.js"></script>
<div class="jumbotron-fluid" id="primary">
<?php
if (isset($_POST['submit'])) {
$from = 'Web_Form_Contact';
$to = 'example#example.com';
$subject = 'Job_Contact';
$c_type = $_POST["c_type"];
if (empty($_POST["c_name"])) {
$errName = 'Info missing: Name';
} else {
$c_name = $_POST["c_name"];
}
if (empty($_POST["c_email"] )) {
$errEmail = 'Please enter a valid email address';
} else {
$c_email = $_POST["c_email"];
}
if (empty($_POST["co_name"])) {
$errCoName = 'Info missing: Company Name';
} else {
$co_name = $_POST["co_name"];
}
if (empty($_POST["j_desc"])) {
$errjDesc = 'Info missing: Job Description';
} else {
$j_desc = $_POST["j_desc"];
}
$body = "From: $c_name\n E-Mail: $c_email\n Type: $c_type\n CoName: $co_name\n Description\n $j_desc";
if (empty($errName && $errEmail && $errCoName && $errjDesc)) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch\n This page will redirect in 5 seconds.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
} else {
echo "$errName\n $errEmail\n $errCoName\n $errjDesc";
}
}
echo "$result";
?>
<div class="container">
<form class="form-horizontal" role="form" method="post" action="php/info.php"
<div class="row">
<div class="col-xs-10 col-sm-6 col-md-6 col-lg-offset-2 col-md-offset-2">
<<h2>Contact Me! <small></small></h2>
<form>
<div class="form-group row">
<label for="clientEmail" class="col-sm-2 form-control-label">Email</label>
<div class="col-sm-10">
<input type="email" name="c_email"class="form-control" id="clientEmail" placeholder="Email" >
</div>
</div>
<div class="form-group row">
<label for="clientName" class="col-sm-2 form-control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="c_name" id="clientName" placeholder="Your Name" >
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">Contact Type</label>
<div class="col-sm-10">
<div class="radio">
<label>
<input type="radio" name="c_type" id="gridRadios1" value="recruiter" checked>
I am a recruiter, and do not work directly for the company hiring.
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="c_type" id="gridRadios2" value="employee">
I work for the company in question, and wish to discuss an open position.
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="c_type" id="gridRadios3" value="other" >
Other
</label>
</div>
</div>
</div>
<div class="form-group row">
<label for="coName" class="col-sm-2 form-control-label">Company Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="co_name" id="coName" placeholder="Company Name" >
</div>
</div>
<!-- Job Description Text Box -->
<div class="form-group row">
<label for="Job Description ">Job Description: (1100 character max!)</label>
<div class="col-sm-10 col-lg-offset-2 col-md-offset-2 col-xl-offset-2 col-sm-offset-2" >
<div class="form-group">
<textarea class="form-control" rows="5" name="j_desc" id="jobDesc" placeholder="Job Description" ></textarea>
<p class="counter">1100</p>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" id="send" name="submit" value="Send"class="btn btn-secondary">Submit</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!--redirect script -->
<script>
function redirect(page) {
setTimeout(function () {
window.location.href = page;
}, 5000);
}
//sends to homepage
redirect("../index.html");
</script>
You need to have an empty check for each variable:
if (empty($errName) && empty($errEmail) && empty($errCoName) && empty($errjDesc)) {
You can also set an email flag at the beginning to true, and if you hit any of the errors, you can set it to false. Then when you're ready to email, check to see if that email flag is still true.

Profile page not displaying user profile information or updating [closed]

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 6 years ago.
Improve this question
Hope someone can help. I have a profile page that I want to display the logged in users details. So far I have this on the Profile page.
<?php
/* This script pulls the existing name input and displays it when the user logs in. */
session_start();
include("db.php"); ?>
<?php include("includes/header.php") ?>
<?php include("includes/nav.php") ?>
<?php
if(logged_in()) {
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
if (!$_POST['name'] && $_POST['name']=="") $error.="<br />Please enter your name";
if (!$_POST['email'] && $_POST['email']=="") $error.="<br />Please enter your email";
if (!$_POST['DOB'] && $_POST['DOB']=="") $error.="<br />Please enter your date of birth";
if (!$_POST['country'] && $_POST['country']=="") $error.="<br />Please enter your country";
if ($error) {
echo '<div class="alert alert-success alert-dismissable">'.addslashes($error).'</div>';
}
if(isset($_POST['form-control'])) {
move_uploaded_file($_FILES['file']['tmp_name'],"img/".$_FILES['file']['name']);
$query = mysqli_query("UPDATE users SET image = '".$_FILES['file']['name']."'");
}
} else {
redirect("login.php");
}
?>
<Style>
.alert{
display:none;
}
#profileimg {
height: 100px;
width: auto;
}
</Style>
<div class="container">
<h1>Edit Profile</h1>
<hr>
<div class="row">
<!-- left column -->
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar img-circle" alt="avatar" id="profileimg">
<h6>Upload a different photo...</h6>
<input class="form-control" type="file" name="name">
</div>
</div>
<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Profile updated.</strong>
</div>
<h3>Personal info</h3>
<form class="form-horizontal" role="form" action="edit_profile.php" method="post">
<div class="form-group">
<label class="col-lg-3 control-label name">name:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['name'];?>" type="text" name="name" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['email'];?>" type="text" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">DOB:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['DOB'];?>" type="date" name="DOB" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['country'];?>" type="text" name="country" required>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" value="Save Changes" type="submit">
<span></span>
<input class="btn btn-default" id="updated" value="Cancel" type="reset">
</div>
</div>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script>
$("#updated").click(function(){
$(".alert").hide().show('medium');
</script>
</body>
</html>
I then have another php file for the updating which is this:
<?php
session_start();
include("db.php");
$name = $_POST['name'];
$email = $_POST['email'];
$DOB = $_POST['DOB'];
$country = $_POST['country'];
$password = md5($salt.$_POST['password']);
$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."'";
$result = mysqli_query($link,$query);
header('Location: profile.php');
?>
So the short is it doesn't display or update and I am not sure why. I am new to PHP so go easy on me if this is simple, I have searched but can't seem to find the answer.
Thanks in advance.
Im also new to this but normally when I check if a SESSION id is active I use
if(isset($_SESSION['id'])) {
$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."' WHERE id='".$_SESSION['id']."'";
}
You also need to echo back the indexed rows that you are trying to query to display results
$name = row['username'];
echo $name;
There are lots of errors in your code: You are trying to upload a file in the same page whereas you send the form data to another page. How you handle form validation is also a little overhead. What I did change in the form is: I add name="save" in your submit button and added new hidden input for storing your user profile id. I am not sure what login() function did in your code, better stick to if($id){}.
Try this:
<?php
/* This script pulls the existing name input
and displays it when the user logs in. */
session_start();
include("db.php");
include("includes/header.php");
include("includes/nav.php");
$id = $_SESSION['id'];
if(loginned()) {//you can do if($id){}
$query="SELECT * FROM users WHERE id='$id' LIMIT 1";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
?>
<style>
.alert{
display:none;
}
#profileimg {
height: 100px;
width: auto;
}
</style>
<div class="container">
<h1>Edit Profile</h1>
<hr>
<div class="row">
<!-- left column -->
<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
<strong>Profile updated.</strong>
</div>
<h3>Personal info</h3>
<form class="form-horizontal" role="form"
action="edit_profile.php" method="post">
<div class="form-group">
<label class="col-lg-3 control-label name">name:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['name'];?>"
type="text" name="name" required>
</div>
</div>
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar
img-circle" alt="avatar" id="profileimg">
<h6>Upload a different photo...</h6>
<input class="form-control" type="file" name="name">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['email'];?>"
type="text" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">DOB:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['DOB'];?>"
type="date" name="DOB" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['country'];?>"
type="text" name="country" required>
</div>
</div>
<div class="form-group">
<input type="hidden" name="id" value="<?php echo $row['id'];?>">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" name="save"
value="Save Changes" type="submit">
<span></span>
<input class="btn btn-default" id="updated"
value="Cancel" type="reset">
</div>
</div>
</form>
</div>
<?php }else{ redirect("login.php"); } ?>
edit_profile.php First we check whether any post with a name of save is there, We validate the posted data. if validation is successful, we proceed to upload your file and then run your update query.
<?php
session_start();
include("db.php");
if(isset($_POST['save'])){
$id = isset($_POST['id'])? $_POST['id']:'';
$name = isset($_POST['name'])? $_POST['name']:'';
$email = isset($_POST['email'])? $_POST['email']:'';
$dob = isset($_POST['DOB'])? $_POST['DOB']:'';
$pass = isset($_POST['passwrd'])? md5($salt.$_POST['password']):'';
$country = isset($_POST['country'])? $_POST['country']:'';
if(empty($name)){
$error = 'Please enter your name';
}elseif(empty($email)){
$error = 'Please enter your email';
}elseif(empty($dob)){
$error = 'Please enter your date of birth';
}elseif(empty($country)){
$error = 'Please enter your country';
}elseif(empty($pass)){
$error = 'Please enter your password';
}else{
move_uploaded_file($_FILES['file']['tmp_name'],"img/".$_FILES['file']['name']);
$query = mysqli_query("UPDATE users SET image = '".$_FILES['file']['name']."'
WHERE id='$id'");
$query = "UPDATE users SET name = '$name', email = '$email',
DOB = '$DOB', country = '$country', password = '$password'
WHERE id='$id'";
$result = mysqli_query($link,$query);
header('Location: profile.php');
}
}
?>
<?php if(!empty($error)){
echo '<div class="alert alert-success
alert-dismissable">'.addslashes($error).'</div>';
}else{
echo '<div class="alert alert-success">Success</div>';
}
?>
I have added a demo here. At least this will help:

PHP form error only present in Internet Explorer

I am working on a PHP form for bootstrap my site. (http://camp.impactak.com/signup.html) This form works perfectly in every browser EXCEPT internet explorer. It comes up with and error:
"Please correct the following error:
YOUR NAME
Hit back button and try again."
I put code in the PHP that should have eliminated an error message if some of the blanks are not filled. However, it still sends an error (only in IE)
PHP:
<?php
/* Set e-mail recipient */
$myemail = "erinpavek#gmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$address = check_input($_POST['inputAddress'], "Street, PO Box, company");
$address2 = check_input($_POST['inputAddress2'], "Apt, Unit, Suite");
$village = check_input($_POST['inputVillage'], "Your Village");
$state = check_input($_POST['inputState'], "State, Providence, Region");
$zip = check_input($_POST['inputZip'], "Your Zip");
$tel = check_input($_POST['inputTel'], "Your Phone");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$pname = check_input($_POST['inputParent'], "Parent/Guardian Name");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");
$select = check_input($_POST['inputSelect'], "Certified");
$select2 = check_input($_POST['inputSelect2'], "NonCertified");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Someone has sent you a message";
$message = "
Someone has sent you a message using your contac form:
Name: $name
Address: $address
Address2: $address2
Village: $village
State: $state
Zip: $zip
Cell: $tel
Email: $email
Parent/Guardian: $pname
Certified: $select
NonCertified: $select2
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://www.camp.impactak.com');
exit();
/* Functions we used */
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
HTML:
<form name="contactform" method="post" action="mailer.php" class="form-horizontal" role="form">
<div class="panel-body">
<form name="contactform" method="post" action="http://wedding-space.net/01_admin_resources/blog/contact_form/mailer.php" class="form-horizontal" role="form">
<div class="form-group">
<label for="inputName" class="col-lg-3 control-label">Full Name</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputName" name="inputName" placeholder="First and Last Name">
</div>
</div>
<div class="form-group">
<label for="inputAddress" class="col-lg-3 control-label">Address1</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputAddress" name="inputAddress" placeholder="Street">
</div>
</div>
<div class="form-group">
<label for="inputAddress2" class="col-lg-3 control-label">Address2</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputAddress2" name="inputAddress2" placeholder="Apt, Unit, Building">
</div>
</div>
<div class="form-group">
<label for="inputVillage" class="col-lg-4 control-label">Village</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputVillage" name="inputVillage" placeholder="Village">
</div>
</div>
<div class="form-group">
<label for="inputState" class="col-lg-4 control-label">State</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputState" name="inputState" placeholder="State">
</div>
</div>
<div class="form-group">
<label for="inputZip" class="col-lg-4 control-label">Zip Code</label>
<div class="col-lg-8">
<input type="text" class="form-control" id="inputZip" name="inputZip" placeholder="Zip">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-3 control-label">Email</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Your Email">
</div>
</div>
<div class="form-group">
<label for="inputParent" class="col-lg-3 control-label">Parent/Guardian</label>
<div class="col-lg-9">
<input type="text" class="form-control" id="inputParent" name="inputParent" placeholder="Parent/Guardian Name">
</div>
</div>
<h5>Each student much choose one class from the either the Certified or Non-Certified class list: </h5>
<select class="form-control" id="inputSelect" name="inputSelect">
<option value="none">Certified Classes</option>
<option value="DriversEd">Drivers Ed. (get license, village youth only)</option>
<option value="NSTC">NSTC- (Seniors or 2014 graduates)</option>
<option value="LifeGuard">Life Guard Training</option>
<option value="ArcticSurvival">Arctic Survival Certification</option>
</select>
<br>
<select class="form-control" id="inputSelect2" name="inputSelect2">
<option value="none">Non-Certified Classes</option>
<option value="cook">Cooking</option>
<option value="Art">Arts from the Earth/Crafts</option>
<option value="poetry">Creative Writing/Poetry</option>
<option value="guitar">Guitar Lessons</option>
<option value="engineering">Science and Engineering</option>
<option value="drama">Drama/Acting</option>
<option value="taeKwonDo">Tae Kwon Do</option>
<option value="sodHouse">Sod House Design</option>
<option value="SkinSewing">Skin Sewing</option>
<option value="DrumDance">Drum Dancing</option>
<option value="Aviation">Aviation</option>
<option value="Rap">Rap/Hip-Hop Class</option>
</select>
<br>
</form>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">
Sign Up
</button>
</div>
</div>
</form>
</div>
</div>
The answer was staring us in the face.
You put a form in a form.
That is not allowed.
you cant have forms submit forms.
Please readjust your markup accordingly to not have forms in Forms, they can be siblings though. Problem solved.
You have:
<form><form></form></form>
You need to either remove the inner form, or separate it out:
<form></form>
or
<form></form>
<form></form>

Categories