Show something while data is being searched on databse - javascript

I want to show a gif while the user's username and password are being validated, but my ajax code isn't storing the submited data, then nothing happens.
login.php (where the inputs are)
<div>
<input type="text" class="css-input" placeholder="Insira seu código" required="" name="codigo" style="background: url(images/icons/user_o.png) no-repeat scroll 5px 5px; background-size: 25px; background-color: #FFFFFF;color: #FF5400;"/>
</div>
<div>
<input type="password" class="css-input" placeholder="Senha" required="" name="senha" style="background: url(images/icons/pwd.png) no-repeat scroll 5px 5px; background-size: 25px;"/>
</div>
login2 (validation form)
<?php
$codigo = mysqli_real_escape_string($conexao, $_POST['codigo']);
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);
$sql_codigo = "SELECT * FROM esc_usuarios WHERE usu_codigo = '$codigo'";
$sql_nome = "SELECT usu_nome FROM esc_usuarios WHERE usu_codigo = '$codigo'";
$sql_nome_resul = mysqli_query($conexao, $sql_nome);
$coluna_bd = mysqli_fetch_assoc($sql_nome_resul);
$result = mysqli_query($conexao, $sql_codigo);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
if(password_verify($senha, $row['usu_senha']))
{
$_SESSION['codigo']=$codigo;
echo '<p><span style="font-family: calibri, sans-serif;"><span style="color: #a1eb8f; font-size: 17pt;">Olá ' . $coluna_bd['usu_nome'] . '! Aguarde um instante...</span></span></p>';
$response['type'] = 'success';
}
else
{
echo '<p><span style="font-family: calibri, sans-serif; color: #ff8f57;"><span style="font-size: 17pt;">Usuário e/ou senha incorretos!</span></span></p>';
$response['type'] = 'failure';
}
echo json_encode($response);
}
}
?>
javascript.js (ajax not working)
$("#login").click(function(){
$.get("login2.php", {codigo: codigo, senha: senha}, function(data){
if (data.type == "success"){
window.location = "index.php";
}
else{
window.location = "login.php";
}
}, "JSON");
});
So, I didn't actually made the gif part yet because I'm trying to at least go through this part, but without success so far.

Related

Telephone field validation using JQuery and PHP

I have a contact form with simple jQuery validation, and sending the form content using Php. I'm trying to include a phone field validation. JavaScript works fine when validating the phone field and auto format/correcting/completing the phone field. However the Php script is not working. It works fine if I remove the the phoneNumber field.
(function($) {
"use strict";
/* Alert Boxes
* ------------------------------------------------------ */
var clAlertBoxes = function() {
$('.alert-box').on('click', '.alert-box__close', function() {
$(this).parent().fadeOut(500);
});
};
/* Contact Form
* ------------------------------------------------------ */
var clContactForm = function() {
/* local validation */
$('#contactForm').validate({
/* submit via ajax */
submitHandler: function(form) {
var sLoader = $('.submit-loader');
$.ajax({
type: "POST",
url: "inc/sendEmail.php",
data: $(form).serialize(),
beforeSend: function() {
sLoader.slideDown("slow");
},
success: function(msg) {
// Message was sent
if (msg == 'OK') {
sLoader.slideUp("slow");
$('.message-warning').fadeOut();
$('#contactForm').fadeOut();
$('.message-success').fadeIn();
}
// There was an error
else {
sLoader.slideUp("slow");
$('.message-warning').html(msg);
$('.message-warning').slideDown("slow");
}
},
error: function() {
sLoader.slideUp("slow");
$('.message-warning').html("Something went wrong! Please try again.");
$('.message-warning').slideDown("slow");
}
});
}
});
};
})(jQuery);
fieldset {
margin: 0;
padding: 0;
}
.message-warning,
.message-success {
display: none;
background: #111111;
font-size: 1.5rem;
line-height: 2;
padding: 3rem;
margin-bottom: 3.6rem;
width: 100%;
}
.message-warning {
color: #ff6163;
}
.message-success {
color: #39b54a;
}
.message-warning i, .message-success i {
margin-right: 10px;
font-size: 1.2rem;
}
/* form loader
* ----------------------------------------------- */
.submit-loader {
display: none;
position: relative;
left: 0;
top: 1.8rem;
width: 100%;
text-align: center;
margin-bottom: 3rem;
}
.submit-loader .text-loader {
display: none;
font-family: "montserrat-regular", sans-serif;
font-size: 1.3rem;
font-weight: bold;
line-height: 1.846;
color: #666666;
letter-spacing: .2rem;
text-transform: uppercase;
}
.oldie .submit-loader .s-loader {
display: none;
}
.oldie .submit-loader .text-loader {
display: block;
}
/* ---------------------------------------------------------------
* ## loader animation
* --------------------------------------------------------------- */
.s-loader {
margin: 1.2rem auto 3rem;
width: 70px;
text-align: center;
-webkit-transform: translateX(0.45rem);
-ms-transform: translateX(0.45rem);
transform: translateX(0.45rem);
}
.s-loader > div {
width: 9px;
height: 9px;
background-color: #FFFFFF;
border-radius: 100%;
display: inline-block;
margin-right: .9rem;
-webkit-animation: bouncedelay 1.4s infinite ease-in-out both;
animation: bouncedelay 1.4s infinite ease-in-out both;
}
.s-loader .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.s-loader .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
<?php
<?php
// Replace this with your own email address
$siteOwnersEmail = 'testemail#outlook.com';
if($_POST) {
$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$phone = stripslashes($_POST['phoneNumber']);
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));
// Check Name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+#[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address.";
}
// Check Phone
if(!preg_match("/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/", $phone)) {
$error['phone'] = "Please enter a valid phone number.";
}
// Check Message
if (strlen($contact_message) < 15) {
$error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Contact Phone: " . $phone . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!$error) {
ini_set("sendmail_from", $siteOwnersEmail); // for windows server
$mail = mail($siteOwnersEmail, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong... Please try again."; }
} # end if - no validation error
else {
$response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
$response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
$response .= (isset($error['phone'])) ? $error['phone'] . "<br /> \n" : null;
$response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;
echo $response;
} # end if - there was a validation error
}
?>
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>
<div class="default-form contact-form">
<form method="post" action="" id="contactForm" novalidate="novalidate">
<fieldset>
<div class="form-group">
<input type="text" name="contactName" id="contactName" value="" placeholder="Complete Name" minlength="4" required="" aria-required="true">
</div>
<div class="form-group">
<input type="email" name="contactEmail" id="contactEmail" value="" placeholder="Your Email" required="" aria-required="true">
</div>
<div class="form-group">
<input placeholder="Phone" type="text" id="phoneNumber" name="phoneNumber" required="" aria-required="true">
<script type="text/javascript">
$('#phoneNumber').inputmask("(999) 999-9999");
</script>
</div>
<div class="form-group">
<input type="text" name="contactSubject" id="contactSubject" value="" placeholder="Subject" required="" aria-required="true">
</div>
<div class="form-group">
<input type="text" name="contactMessage" id="contactMessage" value="" placeholder="Your Message" required="" aria-required="true">
</div>
<div class="form-group">
<button class="full-width btn btn--primary">Submit</button>
<div class="submit-loader">
<div class="text-loader">Sending...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form>
<!-- contact-warning -->
<div class="message-warning">
Something went wrong. Please try again.
</div>
<!-- contact-success -->
<div class="message-success">
Your message was sent, thank you!<br>
</div>
</div>
<!--End Default Form-->
You can preg_match() to validate 10-digit mobile numbers:
preg_match('/^[0-9]{10}+$/', $mobile)
Problem solved.. I changed the inputmask to this format ("999-999-9999"), then also made a change to Php to match the js inputmask, it goes something like:
if(!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
$error['phone'] = "Please enter a valid phone number.";
}
Try this method :
function validating($phone){
$valid_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
$valid_number = str_replace("-", "", $valid_number);
if (strlen($valid_number) < 10 || strlen($valid_number) > 14) {
echo "Invalid Number <br>";
} else {
echo "Valid Number <br>";
}
}
$phone = "(999) 999-9999";
validating($phone);

Webpage refreshes to top on incorrect form submission

If I enter an Incorrect email address or password my site refreshes to the top of the page and I see this error
Incorrect email and Pass
I have to scroll back down to where my form is to see a detailed error.
I want to prevent my page going to the top.
I have searched for a solution on here but can't find anything.
HTML Code:
<body>
<form method="post" style="margin-right:450px;">
<table align="center" cellspacing="3px;">
<tr>
<td>
<input style="border:1px #666 solid; border-radius: 4px; width: 180px; padding: 12px 20px; font-size:18px;" type="email" name="mail" required placeholder="Your Email">
</td>
<td>
<input style="border:1px #666 solid; border-radius: 4px; width: 180px; padding: 12px 20px; font-size:18px;" type="password" name="pass" required placeholder="Your Password">
</td>
</tr>
</table>
<br><br>
<button class="button button3" type="submit" name="log" style="color:#FFF; text-align:center; margin-left:70px;">Log In</button></td>
</form>
</body>
PHP Code:
<?php
$con=mysqli_connect("localhost","root","","form_data");
if(isset($_POST['log']))
{
$_SESSION['mail'] = $_POST['mail'];
$email = $_POST['mail'];
$Password = $_POST['pass'];
$query = mysqli_query($con,"select * from registration where (User_name = '$email' or Email= '$email') and Password = '$Password' ");
$check = mysqli_num_rows($query);
if($check == 1)
{
echo "<h1> User Login <h1>";
header("location:exam.php");
}
else
{
echo "<div class='error'> ";
echo "!! Invalid Username Or Password !!";
echo "</div>";
}
}
?>

php mail() sending mail before form is filled

I have a self posting document that has form fields to fill out with php processing on the same document. My problem is that upon opening the page (website), the message "Message Sent!" shows up immediately before the form can be filled out with information. The php mail() function is linked to my email account so I get the form data email. But no data is sent because the email was sent before the form could be filled out. I want to be able to fill out the form before the email is sent off so that way the form sends actual information. Ive researced this topic and came up with nothing. Any help would be awesome! Here's my code...
<?php
foreach($_POST as $key => $value) //This will loop through each name-value in the $_POST array
{
$tableBody .= "<tr>"; //formats beginning of the row
$tableBody .= "<td>$key</td>"; //dsiplay the name of the name-value pair from the form
$tableBody .= "<td>$value</td>"; //dispaly the value of the name-value pair from the form
$tableBody .= "</tr>"; //End this row
}
echo "<table border='1'>";
echo "<tr><th>Field Name</th><th>Value of field</th></tr>";
foreach($_POST as $key => $value)
{
echo '<tr class=colorRow>';
echo '<td>',$key,'</td>';
echo '<td>',$value,'</td>';
echo "</tr>";
}
echo "</table>";
echo "<p> </p>";
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
background-image: url("rbGrid.png");
background-size: 150%;
background-repeat: no-repeat;
text-align: center;
}
div {
background-color: black;
opacity: 0.9;
color: white;
text-align: center;
}
h1 {
color: white;
}
h2 {
color: white;
}
#borderStyle {
border: double thick red;
border-radius: 45px;
width: 50%;
margin: 0 auto;
}
#hiddenStuff {
display: none;
}
textarea {
display: none;
margin: 0 auto;
}
#mailingInformation {
display: none;
margin: 0 auto;
}
table {
margin: 0 auto;
border: solid thick red;
border-radius: 20px;
}
th {
border: solid thick red;
border-radius: 45px;
}
tr {
color: white;
border: solid thin red;
border-radius: 45px;
}
td {
color: white;
border: solid thin red;
border-radius: 45px;
}
</style>
<script>
function showProductProblemComments()
{
document.getElementById("textarea").style.display = "block";
}
function showMailingListForm()
{
document.getElementById("mailingInformation").style.display = "block";
}
</script>
</head>
<body>
<?php
$toEmail = "robinjennings#nephilim42.com"; //CHANGE within the quotes. Place email address where you wish to send the form data.
//Use your DMACC email address for testing.
$subject = "WDV341 Email Example"; //CHANGE within the quotes. Place your own message. For the assignment use "WDV101 Email Example"
$fromEmail = "robinjennings#nephilim42.com"; //CHANGE within the quotes. Use your DMACC email address for testing OR
//use your domain email address if you have Heartland-Webhosting as your provider.
// DO NOT CHANGE THE FOLLOWING LINES //
$emailBody = "Form Data\n\n "; //stores the content of the email
foreach($_POST as $key => $value) //Reads through all the name-value pairs. $key: field name $value: value from the form
{
$emailBody.= $key."=".$value."\n"; //Adds the name value pairs to the body of the email, each one on their own line
}
$headers = "From: $fromEmail" . "\r\n"; //Creates the From header with the appropriate address
if (mail($toEmail,$subject,$emailBody,$headers)) //puts pieces together and sends the email to your hosting account's smtp (email) server
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
/*$inName = $_POST["Name"];
$inEmail = $_POST["Email Address"];
$inAddress = $_POST["address"];
$inReason = $_POST["Reason"];
$inComments = $_POST["comments"];
$inMailBox = $_POST["Mailing List"];
$inUseAddress = $_POST["checkForAddress"];
$inFirstName = $_POST["mailingName"];
$inLastName = $_POST["mailingLastName"];
//$inMailingAdd $_POST["mailingAddress"];
$inPhoneNumber = $_POST["phoneNumber"];
$inMoreInfo = $_POST["More Info"];*/
?>
<h1>WDV341 Intro PHP</h1>
<h2>Programming Project - Contact Form</h2>
<div>
<form name="form1" method="POST" action="contactForm2.php">
<p> </p>
<p>
<div id = "borderStyle">
<label>Your Name:
<input type="text" name="Name" id="textfield" required>
</p>
<br><br>
<p>Your Email:
<input type="text" name="Email Address" id="textfield2" required>
</p>
<br><br>
<p>Your Address:
<input type = "text" name = "address" id = "living">
</p>
<br><br>
<p>Reason for contact:
<select name="Reason" id="select2" onChange = "showProductProblemComments()" required>
<option value="default">Please Select a Reason</option>
<option value="product">Product Problem</option>
<option value="return">Return a Product</option>
<option value="billing">Billing Question</option>
<option value="technical">Report a Website Problem</option>
<option value="other">Other</option>
</select>
</p>
<br><br>
<p>Comments:
<textarea name="comments" id="textarea" cols="45" rows="5"required></textarea>
</p>
<br><br>
<p>
<input type="checkbox" name="Mailing List" id="checkbox" onClick = "showMailingListForm()">
Please put me on your mailing list.
</p>
<div id = "mailingInformation">
<h3>Please fill out the form below to be put on the mailing list to recieve coupons and special offers</h3>
<p>Check the box to use address above
<input type = "checkbox" name = "checkForAddress" id = "checkAddress">
</p>
<p>First Name:
<input type = "text" name = "mailingName" id = "mailing">
</p>
<p>Last Name:
<input type = "text" name = "mailingLastName" id = "mailingLast">
</p>
<p>Mailing Address:
<input type = "text" name = "mailingAddress" id = "mailingAdd">
</p>
<p>Phone Number(Optional)
<input type = "text" name = "phoneNumber" id = "phone">
</p>
</div>
<p>
<input type="checkbox" name="More Info" id="checkbox2">
Send me more information about your products.</label>
</p>
<br><br>
<p>
<input type="hidden" name="hiddenField" id="hidden" value="application-id:US447">
</p>
<br><br>
<p>
<input type="submit" name="button" id="button" value="Submit">
<input type="reset" name="button2" id="button2" value="Reset">
</p>
<div>
</form>
<div id = "hiddenStuff">
<p>
<table border='a'>
<tr>
<th>Field Name</th>
<th>Value of Field</th>
</tr>
<?php echo $tableBody; ?>
</table>
<!--</p>
<p>Name: <?php echo $inName; ?></p>
<p>Email: <?php echo $inEmail; ?></p>
<p>Address: <?php echo $inAddress; ?></p>
<p>Reason: <?php echo $inReason; ?></p>
<p>Comments: <?php echo $inComments; ?></p>
<p>Mailing List: <?php echo $inMailBox; ?></p>
<p>Use Previous Address Given: <?php echo $inUseAddress; ?></p>
<p>First Name: <?php echo $inFirstName; ?></p>
<p>Last Name?: <?php echo $inLastName; ?></p>
<p>Mailing Address: <?php echo $inMailingAdd; ?></p>
<p>Phone Number: <?php echo $inPhoneNumber; ?></p>
<p>More Information: <?php echo $inMoreInfo; ?></p>-->
</div>
</body>
</html>
Some line of code have been commented out for the sake of experimenting. Thank you in for the help.
That's because of this:
<?php
$toEmail = "robinjennings#nephilim42.com"; //CHANGE within the quotes. Place email address where you wish to send the form data.
//Use your DMACC email address for testing.
//Example: $toEmail = "jhgullion#dmacc.edu";
$subject = "WDV341 Email Example"; //CHANGE within the quotes. Place your own message. For the assignment use "WDV101 Email Example"
$fromEmail = "robinjennings#nephilim42.com"; //CHANGE within the quotes. Use your DMACC email address for testing OR
//use your domain email address if you have Heartland-Webhosting as your provider.
//Example: $fromEmail = "contact#jhgullion.org";
// DO NOT CHANGE THE FOLLOWING LINES //
$emailBody = "Form Data\n\n "; //stores the content of the email
foreach($_POST as $key => $value) //Reads through all the name-value pairs. $key: field name $value: value from the form
{
$emailBody.= $key."=".$value."\n"; //Adds the name value pairs to the body of the email, each one on their own line
}
$headers = "From: $fromEmail" . "\r\n"; //Creates the From header with the appropriate address
if (mail($toEmail,$subject,$emailBody,$headers)) //puts pieces together and sends the email to your hosting account's smtp (email) server
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>
You have to check if your form is submitted then the above code executes. So put the above code in:
if( isset($_REQUEST['form_element_index']) )
{
// Above code here
// Now the code executes when form is submitted
}
Its happening because you have't created a form and asked user to give input.What you have to do is create a form and then retreive the form values and upon submitting the form send the mail.It would definitely work....

reset password show password reset but when try to login again it doesn't work

Hello I tried to put forgot password on my web but I have a little problem. I can send the mail to the person who want to reset their password but when the person resets their password it shows password reset but when I try to login with the new password it doesn't work. Only the old one works. Here is my reset.php file:
<?php
include('db.php');
if(isset($_GET['action']))
{
if($_GET['action']=="reset")
{
$encrypt = mysqli_real_escape_string($connection,$_GET['encrypt']);
$query = "SELECT id FROM user where md5(90*13+id)='".$encrypt."'";
$result = mysqli_query($connection,$query);
$Results = mysqli_fetch_array($result);
if(count($Results)>=1)
{
}
else
{
$message = 'Invalid key please try again. Forget Password?';
}
}
}
elseif(isset($_POST['action']))
{
$encrypt = mysqli_real_escape_string($connection,$_POST['action']);
$password = mysqli_real_escape_string($connection,$_POST['password']);
$query = "SELECT id FROM user where md5(90*13+id)='".$encrypt."'";
//echo $query;
$result = mysqli_query($connection,$query);
$Results = mysqli_fetch_array($result);
if(count($Results)>=1)
{
$query = "update user set password='".md5($password)."' where id='".$Results['id']."'";
mysqli_query($connection,$query);
// echo $query;
$message = "Votre mot de passe changé avec succès Cliquez ici pour vous identifier.";
}
else
{
$message = 'Clé non valide se il vous plaît essayer à nouveau. Mot De Passe Oublié?';
}
}
else
{
header("location: /ocelles/make/fg");
}
$content ='<script type="text/javascript" src="jquery-1.8.0.min.js"> </script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style type="text/css">
input[type=password]
{
border: 1px solid #ccc;
border-radius: 3px;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
width:200px;
min-height: 28px;
padding: 4px 20px 4px 8px;
font-size: 12px;
-moz-transition: all .2s linear;
-webkit-transition: all .2s linear;
transition: all .2s linear;
}
input[type=password]:focus
{
width: 400px;
border-color: #51a7e8;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1),0 0 5px rgba(81,167,232,0.5);
outline: none;
}
</style>
<script>
$(function() {
$( "#tabs" ).tabs();
});
function mypasswordmatch()
{
var pass1 = $("#password").val();
var pass2 = $("#password2").val();
if (pass1 != pass2)
{
alert("Les mots de passe ne correspondent pas");
return false;
}
else
{
$( "#reset" ).submit();
}
}
</script>
</head>
<body>
<b>'.$message.'</b>
<div id="tabs" style="width: 480px;">
<ul>
<li>Réinitialiser mot de passe</li>
</ul>
<div id="tabs-1">
<form action="reset.php" method="post" id="reset" >
<p><input id="password" name="password" type="password" placeholder="Entrez nouveau mot de passe">
<p><input id="password2" name="password2" type="password" placeholder="Retaper nouveau mot de passe">
<input name="action" type="hidden" value="'.$encrypt.'" /></p>
<p><input type="button" value="Réinitialiser mot de passe" onclick="mypasswordmatch();" /></p>
</form>
</div>
</div>';
$pre = 1;
$title = "How to create Login and Signup form in PHP";
$heading = "How to create Login and Signup form in PHP.";
include("html.inc");
?>
Seems like you're using mysqli_real_escape_string to sanitize and to escape special characters on $encrypt, but this string may have special characters. Make sure if mysqli_real_escape_string function isn't removing any character from $encrypt value.
I'm not sure what this part of your code is doing:
...} elseif(isset($_POST['action'])) {
$encrypt = mysqli_real_escape_string($connection,$_POST['action']);
$password = mysqli_real_escape_string($connection,$_POST['password']);
$query = "SELECT id FROM user where md5(90*13+id)='".$encrypt."'";
//echo $query;
$result = mysqli_query($connection,$query);
$Results = mysqli_fetch_array($result);
if(count($Results)>=1) {
$query = "update user set password='".md5($password)."' where id='".$Results['id']."'";
mysqli_query($connection,$query);
$message = "Votre mot de passe changé avec succès Cliquez ici pour vous identifier.";
}...
Seems like you're trying to match the user id with $_POST['action'] encrypted and probably not finding any match on database.

Clear input with submit button

Switching over from C# to PHP for a bit and not seeing what I am doing wrong here.
What I am wanting to to is when I click the submit button - I want the email sent (like it is doing) but then I want the input text fields to clear out the old text the user had previously input.
The one way I had it figured out would clear my test before it was actually submitted, which didn't help me very much.
Any input on how to do this?
<?php
/*
* Template Name: Contact
* Description: Contact Us
*/
get_header();
?>
<div class="container">
<div class="section group">
<div class="col span_2_of_2">
<h1> Contact Us <h1>
<p style="font-size:16px"> Radiology Services LLC is located on the east side of Evansville, IN off the Robert D. Orr Highway.</p>
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3146.027108890167!2d- 87.45272299999999!3d37.953153!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x170f5925d75e6135!2s Radiology+Services+LLC!5e0!3m2!1sen!2sus!4v1404175203674" width="100%" height="350px" frameborder="0" style="border:0"></iframe>
</div>
<div class="col span_1_of_2" style="padding-left:40px;>
<?php
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
//php mailer variables
$to = 'aje#gmail.com';
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent);
else my_contact_form_generate_response("error", $message_unsent);
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="entry-content">
<?php the_content(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
.subBtn{
width:100%;
border-radius: 0px;
background-color:#5bb75b;
color:#FFFFFF;
}
.subBtn:hover{
background-color:#408140;
}
.m{
width:100%;
border-radius: 0px;
}
</style>
<script language="javascript">
fromreset()
{
myform.reset();
document.myform.[textbox Id] = " ";
}
</script>
<form name="myform" id="myform"action="<?php the_permalink(); ?>" method="post">
<label for="name" class="m">Name: <span>*</span> <br>
<input type="text" class="m" id="name" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>">
</label>
<label for="message_email" class="m">Email: <span>*</span> <br>
<input type="text" class="m" id="email" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>">
</label>
<label for="message_text" class="m" id="mu">Message: <span>*</span> <br>
<textarea type="text" class="m" id="textm" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea>
</label>
<label for="message_human" class="m">Human Verification: <span>*</span> <br>
<input type="text" class="m" name="message_human"> + 3 = 5
</label>
<input type="hidden" name="submitted" value="1" class="m">
<input type="hidden" name="submitted" value="1" style="width:100%">
<input type="submit" value="submit" class="subBtn" onclick="formreset();">
<?php echo $response; ?>
</form>
</div>
</div>
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div>
<?php get_footer(); ?>

Categories

Resources