where clause in PHP /mysql
how can i pass vraiable in mysql i have folling code
Code:
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$result = mysql_query("SELECT * FROM login_db where LoginID= 'demo' and loginpassword1= 'demo' ");
I neeed to pas values in variables $username and $password
please corrrect above where clause
Re: where clause in PHP /mysql
You can do it like this:
PHP Code:
$username = $_POST['username']; // I think it is more appropriate to use the $_GET or $_POST based on the request method instead of using global $_REQUEST which contains the data of GET, POST & COOKIES
$password = $_POST['password'];
$result = mysql_query("SELECT * FROM login_db where LoginID= '$username' and loginpassword1= '$password' ");
Or, you could append the variables using dot.
Eg:
PHP Code:
$result = mysql_query("SELECT * FROM login_db where LoginID= '" . $username . "' and loginpassword1= '" . $password . "' ");
Also, it would be a good choice to use escape the user inputs before using it in a query. Because otherwise it would be prone to sql injections !
:wave:
Re: where clause in PHP /mysql
Re: where clause in PHP /mysql
thnaks for reply
see my code
Code:
$result = mysql_query("SELECT * FROM login where LoginID= '$username' and Password1= '$password' ");
if($result)
{
echo "success";
}
else
{
echo "There were no results for your search";
}
also
Code:
<script type="text/javascript">
$(document).ready(function() {
$("#login").click(function() {
var action = $("#form1").attr('action');
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response)
{
if(response == 'success')
$("#form1").slideUp('slow', function() {
$("#message").html("<p class='success'>You have logged in successfully!</p>");
});
else
{
// echo response;
$("#message").html("<p class='error'>Invalid username and/or password.</p>");
}
}
});
return false;
});
});
</script>
if i input wron password it also show me message
You have logged in successfully ..please mention if need full code
Re: where clause in PHP /mysql
How do I make mod_rewrite suppress processing more rules?
Re: where clause in PHP /mysql
try this code
Code:
<?php
$result = mysql_query("SELECT * FROM login where LoginID= '$username' and Password1= '$password' ");
if(mysql_num_rows($result) > 0) # OR mysql_num_rows($result) == 1
{
echo "success logged in";
}
else
{
echo "Invalid login";
}
?>
Re: where clause in PHP /mysql
Quote:
Originally Posted by
adhp123
How do I make mod_rewrite suppress processing more rules?
Use the [L] flag : http://www.easymodrewrite.com/notes-last
:wave:
Re: where clause in PHP /mysql
Re: where clause in PHP /mysql
Quote:
Originally Posted by
adhp123
Thqanks you
Next time, you should post your question in your own thread. Don't hijack others. :p
:wave:
Re: where clause in PHP /mysql
Re: where clause in PHP /mysql
thanks to all
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Login with jQuery AJAX</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#login").click(function() {
var action = $("#form1").attr('action');
var form_data = {
username: $("#username").val(),
password: $("#password").val(),
is_ajax: 1
};
$.ajax({
type: "POST",
url: action,
data: form_data,
success: function(response)
{
if(response == 'success')
$("#form1").slideUp('slow', function() {
$("#message").html("<p class='success'>You have logged in successfully!</p>");
$("#Topic").html("<p class='success'>dsdsd</p>");
});
else
{
// echo response;
$("#message").html("<p class='error'>Invalid username and/or password.</p>");
}
}
});
return false;
});
});
</script>
</head>
<body>
<p> </p>
<div id="content">
<h1>Login Form</h1>
<form id="form1" name="form1" action="doLogin.php" method="post">
<p>
<label for="username">Username: </label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" id="login" name="login" value ="Login" />
</p>
<div id="Topic"></div>
</form>
<div id="message"></div>
<div>
</body>
</html>
i have this staus . now i want to display rows from database in div
(<div id="Topic"></div>)
in tabular format or datalist in .Net .. For example data like
1 --- Topic 1
2 --- Topic 2
3 --- Topic 3
can any one help me