Jump to content

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


supergrame

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.

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.