-
Apr 22nd, 2012, 09:16 AM
#1
Thread Starter
Hyperactive Member
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
-
Apr 22nd, 2012, 11:40 PM
#2
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 !
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Apr 22nd, 2012, 11:40 PM
#3
Hyperactive Member
Re: where clause in PHP /mysql
-
Apr 24th, 2012, 12:19 PM
#4
Thread Starter
Hyperactive Member
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
-
Apr 25th, 2012, 08:36 AM
#5
Banned
Re: where clause in PHP /mysql
How do I make mod_rewrite suppress processing more rules?
-
Apr 26th, 2012, 01:42 PM
#6
Fanatic Member
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";
}
?>
-
Apr 26th, 2012, 01:45 PM
#7
Re: where clause in PHP /mysql
Originally Posted by adhp123
How do I make mod_rewrite suppress processing more rules?
Use the [L] flag : http://www.easymodrewrite.com/notes-last
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Apr 26th, 2012, 07:44 PM
#8
Banned
Re: where clause in PHP /mysql
-
Apr 26th, 2012, 10:20 PM
#9
Re: where clause in PHP /mysql
Originally Posted by adhp123
Thqanks you
Next time, you should post your question in your own thread. Don't hijack others.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Apr 26th, 2012, 10:36 PM
#10
Banned
Re: where clause in PHP /mysql
-
May 1st, 2012, 01:23 AM
#11
Thread Starter
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|