LANGUAGE JAVASCRIPT, PHP
Need help with PHP and ajax code. The user needs to login but, I keep getting an error that I coded "Wrong username and password!" ***PLEASE DONT GIVE ME A NEW CODE THAT IS NOWHERE NEAR THE CODE I SUBMITTED***** PLEASE LOOK AT THE CODE AND SEE ANY ISSUES
login.html
<!DOCTYPE html>
<html>
<head>
<title>login popup</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style type="text/css">
body {
background-color: white;
}
</style>
</head>
<body>
<center>
<h1 style="text-align: center;"> Login </h1>
<form>
Login ID: <input type='text' size='30' id='ID' placeholder="username" required='required'/><br><br>
Password: <input type='password' size='30' id='pwd' placeholder="password" required='required'/><br><br>
<input type='button' id='submit' value='Submit'>
<input type='button' id='close' value='close' onclick='self.close()'>
<div id='result'></div>
</form>
</center>
<script type="text/javascript">
$(document).ready(function()
{
$('#submit').click(function()
{
var ID = $("#ID").val();
var pwd = $("#pwd").val();
if(ID != "" && pwd != "")
{
$.ajax
({
type:'POST',
url: 'login2.php',
data: {
username1: ID,
password1: pwd
},
success: function(response){
if(response == 1){
var con = confirm("Login Success! \n Click OK to continue! ");
if(con == true){
document.cookie ="p1UserName="+ID+"; expires=Fri, 31 Dec 9999 23:59:59 GMT";
self.close();
}
}else{
document.getElementById("result").innerHTML ="Wrong username and password!";
}
},
error: function(response) {
alert(response);
}
});
}else{
document.getElementById("result").innerHTML ="Enter username and password! ";
}
});
});
</script>
</body>
</html>
login.php
<?php
if($_SERVER['REQUEST_METHOD'] == POST){
define("IN_CODE, 1");
include("dbconfig.php");
$uname = mysqli_real_escape_string($con, $_POST['username1']);
$password = mysqli_real_escape_string($con, $_POST['password1']);
$query = "SELECT * FROM DV_User WHERE login = '$login' and password= '$password'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result)<1){
echo 0;
}
else{
echo 1;
}
exit();
}
?>
------login and password should be correct-------
The PHP code you had written -
<?php
if($_SERVER['REQUEST_METHOD'] == POST){
define("IN_CODE, 1");
include("dbconfig.php");
$uname = mysqli_real_escape_string($con, $_POST['username1']);
$password = mysqli_real_escape_string($con, $_POST['password1']);
$query = "SELECT * FROM DV_User WHERE login = '$login' and password= '$password'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result)<1){
echo 0;
}
else{
echo 1;
}
exit();
}
?>
But in this define("IN_CODE, 1"); is incorrect. The correct syntax is - define("IN_CODE",1);
And the select query i.e. "SELECT * FROM DV_User WHERE login = '$login' and password= '$password'"; is incorrect.
In this, login = '$login' where $login is not defined. Instead you have to write login = '$uname'. Because $uname variable getting the value of username not the $login variable.
So, the "mysqli_num_rows($result)" always return zero.
Hence the response variable always gets 0. So the else part is executed and then print "Wrong username and password!"
The correct query is -
"SELECT * FROM DV_User WHERE login = '$uname' and password= '$password'";
LANGUAGE JAVASCRIPT, PHP Need help with PHP and ajax code. The user needs to login but,...
NEED HELP with HTML with Javascript embedding
for form validation project below. I have my code
below but I'm stuck with validation. If anyone can fix it, I'd
really appreciate.
******************************************************************************
CODE:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project
Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Nice</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<script>
var textFromTextArea;
function getWords(){
var text =...
How can I print the Database table in PHP please ? here I have form for name and email, also I have php code that allow user to add his name and email to my database, all I need to print my final database when the user click on submit. <form action="" method="post"> <label>Name :</label> <input type="text" name="name" required="required" placeholder="Please Enter Name"/><br /><br /> <label>Email :</label> <input type="email" name="email" required="required" /><br/><br /> <input type="submit" value=" Submit " name="submit"/><br /> </form>...
How can I connect the html forms to php --> mysql database <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h2> <center> Average: </h2> <h3> <center> Rate the following: </h2> <h3> <center> Rating Criteria: <br> Developing (0-5), Competent (6-10), Accomplished (10-15); </h3> <center> Judge Name: <input type="text" id="judge"> <br> <br> <center> 1. Articulate requirements and design of the project: <input type="text" id="num1"> <br> <br> 2. Plan the solution and implement the project: <input type="text" id="num2"> <br> <br> 3....
Add comments to it by filling in the blank comments numbers 1 through 32. (The first few comments are HTML comments, not JavaScript comments, and are bracketed according to <!- this is an HTML comment>.) <!DOCTYPE html> <html> <body onload="handleFormAction()"> <h2>Form handling example in JavaScript</h2> <h3>(Or, John Doe meets Robbie Robot)</h3> <h4>Instructions: Fill in the form. Then fill in comments 1 through 23 in the JavaScript code!</h4> <form target="_blank" action= > <!- 1: replace this placeholder HTML comment with a...
Hey Guys I am doing a project and need some help with code in HTML and PHP. I need a form made in HTML that can be sent to a specific email through PHP. For some reason the info is not getting sent to my email, even though it says that it was sent. I have some source code here: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $email = mail('MY_EMAIL', $subject, $message,...
PHP code that is given :
<?php
// Here is where your preprocessing code goes
// An example is already given to you for the First Name
$fname = $_GET['fname'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exercise 2 - GET Echo</title>
<style>
body {
margin:0;
padding:0;
font-family: Arial;
}
form {
margin:20px;
}
input[type="text"], input[type="password"] {
width:150px;
padding:3px;
font-size:1em;
}
input[type="submit"] {
padding:3px;
font-size:1em;
}
label {
display:inline-block;
width:150px;
}
.input-container {
padding:5px;
}
</style>
</head>
<body>
<form...
I need to complete 3 validation cases in this Javascript code. I need to validate email, phone and street address. How would I go about validating these 3 cases in this code: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Week 10: Regular Expressions</title> <style type="text/css"> span { padding: 2px; } .success { color: #008000; background: #99cc99; } .failure { color: #ff0000; background: #ff9999; } </style> <script type="text/javascript"> function validateInput(form) { var result0 = document.getElementById('result0'), result1 = document.getElementById('result1'), result2 = document.getElementById('result2'),...
<html> <head> <title>Sign Up page</title> <form name="validationForm" method="post" onsubmit="return checkvalidation()"> <!--div class--> <div class="formvalidation"> <label>Your first Name</label> <span id="showname"></span> <!--label for firstname--> <input type="text" name="firstname" class="formsignup" id ="firstn" placeholder="Enter your Name"> <br><br> <!--lastname--> <label>Your last Name</label> <span id="showlname"></span> <input type="text" name="lastname" class="formsignup" id="lastn" placeholder="Enter your last Name"> <br><br> <!--email--> <label>Your Email</label> <span id="showemail"></span> <input type="email" name="emailid" class="formsignup" size="45" id="emailn" placeholder="Enter your Email"> <br><br> <input type="submit" value="send"> </div> </form> <script> function checkvalidation(){ var name = document.forms["validationForm"]["firstname"].value; var lname...
For this code below, I need to add the form information to mysql when I click on submit, at the same time when I click on submit I need to move to another page like Welcome.php WITH NOTE THAT THE ENTERED INFORMATION NOW ALREADY IN DATABASE how can I male that with my code below? THANKS ................................................................................................................................................ <form method="POST"> <div class="container"> <label for="fname"><b>First Name</b></label> <input type="text" placeholder="Enter First Name" name="fname" required> <label for="lname"><b>Last Name</b></label> <input type="text" placeholder="Enter Last Name"...
Modify this code to store the form elements as variables and display them on the page in an HTML table. <!DOCTYPE html> <html> <head> <script> function getValues() { var result = ""; result += "First Name: " + document.forms["myForm"]["fname"].value + "<br>"; result += "Last Name: " + document.forms["myForm"]["lname"].value + "<br>"; result += "Address: " + document.forms["myForm"]["address"].value + "<br>"; result += "City: " + document.forms["myForm"]["city"].value + "<br>"; result += "State: " + document.forms["myForm"]["state"].value + "<br>"; document.getElementById("output").innerHTML = result; } </script>...