Jump to content

[SOLVED] how do you add the $_POST into SELECT * FROM users WHERE password='$password


Recommended Posts

$sql="SELECT * FROM users WHERE username="$_POST['username']" and password='$mypassword'";

$result=mysql_query($sql);

 

i dont want to use varibles only the global vars

insted of having this extra code i dont need

 

$mypassword = $_POST['password'];

 

 

<?php

if (isset($_POST['username']) && isset($_POST['password']))

{

$username = htmlentities($_POST['username']);
$mypassword = htmlentities($_POST['password']);

$sql="SELECT * FROM users WHERE username="$_POST['username']" and password='$mypassword'";
$result=mysql_query($sql);

if (mysql_num_rows($result) >0 )

{

echo "Logged In";

}

}

?>

Your missing some syntax, the ".", which concatenates strings and the single quotes encapsulating the username.

 

$sql = "SELECT * FROM `users` WHERE `username`='".$_POST['username']."' and `password`='$mypassword'";

 

You should be cleansing your data before you start using it in SQL queries, otherwise you could/will suffer from SQL injection attacks.

Parse error: parse error in C:\wamp\www\public\includes\login.php on line (18)

 

 

(18)  $sql="SELECT * FROM users WHERE username="$_POST['username']" and password='$mypassword'";

 

Parse error: parse error in C:\wamp\www\public\includes\login.php on line (18)

 

 

(18)  $sql="SELECT * FROM users WHERE username="$_POST['username']" and password='$mypassword'";

 

See my post above, you're missing the concatenation periods.

You should also use mysql_real_escape_string().

 

Was just going to say that. You should really filter this data first. That is THE most insecure way of checking data in a mysql table.

ok well the reson for my wanting to do that is that my login table and the php are all in the same page. and i get this error

 

Notice: Undefined index: password in C:\wamp\www\public\includes\login.php on line 7

 

 

so if there is a work around that would be good.

 

im calling login.php from index.php (incase you never guessed that)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.