Jump to content

Selecting from that row / column only.


Imtehbegginer

Recommended Posts

My code:
[code]<?php
// LOGIN
include 'includes/connect.php';
$query_select_login = mysql_query("SELECT username FROM accounts WHERE username = '".$_POST['username']."'");
$query_rows = mysql_num_rows($query_select_login);
// Check for the username above.
// Now we check the rows
if($query_rows = 0) {
die("There is no such username in the database.");
} else {
echo "";
}
$query_select_pass = mysql_query("SELECT password FROM accounts WHERE password = '".$_POST['password']."'");
// THIS IS WHERE PHPFREAKS HELPS ME.[/code]

How can I make the password select from the row of that username?
Link to comment
Share on other sites

The question is why are you trying to do this in two queries? Try...

[code=php:0]
"SELECT username FROM accounts WHERE username = '{$_POST['username']}' && password = '{$_POST['password']}'"
[/code]

This gets it all done in one query. However, be aware that using the $_POST[] variables directly in your query like that opens your database to sql injections. You'll should clean and validate the data first.

Link to comment
Share on other sites

first off, never take user inputted data straight to the database the way you are doing. at least clean it up before you post it in your query.

but to answer yoru question all you have to do is add AND username = '". $username . "' to your second query. //where $username = $_POST['username'] <--do some clean up at this point
Link to comment
Share on other sites

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.