Jump to content

[SOLVED] HELP!!!!


Recommended Posts

i have been going nuts for 2 months now trying to get 1 line of PHP code to work. its simple and straight forward but doesnt wish to work for somereason. a little background before i post it here.  i have another php working to enter info into my table and it works fine, however to cross reference that info doesnt work. it eitheer ALWAYS gives me a result or NEVER gives me a result and it is driving me nuts. please understnand if i dont list the passwords and connections. the connections connect and are fine, the "post" info from the form is fine. everytnhing but the result works. i am starting it for a password and login script but until i can get the fiundamentals working, no need to work ont he rest. thank you for any help. my mysql shows the querys but shows them as SELECT FROM users WHERE 1. so here is the code if anyone can see the problems, please let me know. and i have tried many different formats from investiugating online to no avail. thank you. here is the code. the "echos" are merely for trouble shooting.

 

 

<?php

$conn = mysql_connect("localhost", name, password) or die("can not connect");

 

 

 

$db = mysql_select_db(database, $conn) or die ("can not connect");

 

 

 

$username = $_POST["username"];

$password = $_POST["password"];

echo $username;

echo;

echo $password;

echo;

$result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found.");

echo $result;

 

echo "good job";

mysql_close($conn);

 

?>

 

 

thanks for any help.

Joey D.

Link to comment
Share on other sites

Well i would do this:

<?php
$conn = mysql_connect("localhost", name, password) or die("can not connect"); 

$db = mysql_select_db(database, $conn) or die ("can not connect");

$username = $_POST["username"];
$password = $_POST["password"];
echo $username;
echo $password;
$result = mysql_query("SELECT * FROM users WHERE uname = \"". $username. "\" AND pword = \""$password. "\") or die ("Login and/or Password not found.");
echo $result;

echo "good job"; 
mysql_close($conn);

?>

 

I removed the ,$CONN from there as i didn't see what it done... maybe someone less thick then me can figure it out...

 

But i don't see the point of blank echo commands... what are they trying to do???

 

from looking at ur code that's all i can figure out!

 

:)

Link to comment
Share on other sites

Try This

 


$conn = mysql_connect("localhost", name, password) or die("can not connect");



$db = mysql_select_db(database, $conn) or die ("can not connect");



$username = $_POST["username"];
$password = $_POST["password"];

echo $username;
echo $password;

$result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found.");

$row = mysql_fetch_array($result);

$uname = $row['uname'];

echo "$uname";
mysql_close($conn);

Link to comment
Share on other sites

Try This

 


$conn = mysql_connect("localhost", name, password) or die("can not connect");



$db = mysql_select_db(database, $conn) or die ("can not connect");



$username = $_POST["username"];
$password = $_POST["password"];

echo $username;
echo $password;

$result = mysql_query("SELECT * FROM users WHERE uname = '$username' AND pword = '$password' ",$conn) or die ("Login and/or Password not found.");

$row = mysql_fetch_array($result);

$uname = $row['uname'];

echo "$uname";
mysql_close($conn);

 

i knew i was forgetting something...

 

loud trance music and 6 beers kinda kills the skills ;-) hhahaha

Link to comment
Share on other sites

the "die" will only be executed if the mysql query fails...not if it returns a result meaning that the username and password were not found.

 

$conn = mysql_connect("localhost", name, password) or die("can not connect");
$db = mysql_select_db(database, $conn) or die ("can not connect");

$username = $_POST["username"];
$password = $_POST["password"];

$result = mysql_query("SELECT id FROM users WHERE uname = '$username' AND pword = '$password' ", $conn) or die ("Error in query: " . mysql_error());

if (mysql_num_rows($result) == 1) {
echo "Username / Password combo found";
} else if (mysql_num_rows($result) > 1) {
echo "Username / Password error - multiple entries";
} else {
echo "Username / Password combo not found";
}

mysql_close($conn);

 

Note the difference in the "die" statement.

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.