Results 1 to 11 of 11

Thread: where clause in PHP /mysql

  1. #1
    Hyperactive Member
    Join Date
    Oct 07
    Posts
    270

    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

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,559

    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  3. #3
    Addicted Member
    Join Date
    Dec 09
    Location
    sydney
    Posts
    187

    Re: where clause in PHP /mysql

    ....

  4. #4
    Hyperactive Member
    Join Date
    Oct 07
    Posts
    270

    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

  5. #5
    Banned
    Join Date
    Apr 12
    Posts
    6

    Re: where clause in PHP /mysql

    How do I make mod_rewrite suppress processing more rules?

  6. #6
    Fanatic Member
    Join Date
    Aug 07
    Posts
    808

    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";
    				}
    				?>

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,559

    Re: where clause in PHP /mysql

    Quote Originally Posted by adhp123 View Post
    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  8. #8
    Banned
    Join Date
    Apr 12
    Posts
    6

    Re: where clause in PHP /mysql

    Thqanks you

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,559

    Re: where clause in PHP /mysql

    Quote Originally Posted by adhp123 View Post
    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 Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  10. #10
    Banned
    Join Date
    Apr 12
    Posts
    6

    Re: where clause in PHP /mysql

    yes I get it

  11. #11
    Hyperactive Member
    Join Date
    Oct 07
    Posts
    270

    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>&nbsp;</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
  •