Jump to content


Photo

whats wrong with this?


  • Please log in to reply
5 replies to this topic

#1 -Felix-

-Felix-
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 06 October 2005 - 01:13 PM

mysql_connect ("localhost", "login", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("login_database"); 

$username=$_POST['user'];
echo $_POST['user'];

$result=mysql_query("SELECT * FROM Profiles WHERE Email = $username");

   $row=mysql_fetch_assoc($result);
$SQLEmail=$row['Email'];
$SQLPassword=$row['Password'];

I get an error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/account/public_html/account.php on line 23



#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2005 - 01:18 PM

mysql_connect ("localhost", "login", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("login_database"); 

$username=$_POST['user'];
echo $_POST['user'];

$result=mysql_query("SELECT * FROM Profiles WHERE Email = $username");

   $row=mysql_fetch_assoc($result);
$SQLEmail=$row['Email'];
$SQLPassword=$row['Password'];

I get an error

View Post


most likely you're getting the error since you don't have quotes around $username in your query:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM Profiles WHERE Email = '$username';
[!--sql2--][/div][!--sql3--]
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 -Felix-

-Felix-
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 06 October 2005 - 01:22 PM

nope, doesnt work either.

Somehow Im guessing that there is something wrong with the "Email" Im using as an index? In the database admin I have set Email-field as a Primary field, but it is not an index field. Could this be causing the problem?

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2005 - 01:37 PM

nope, doesnt work either.

Somehow Im guessing that there is something wrong with the "Email" Im using as an index? In the database admin I have set Email-field as a Primary field, but it is not an index field. Could this be causing the problem?

View Post


don't know... just run an "or die(mysql_error())" right after your query:
[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
[span style=\"color:#0000BB\"]<?php
$result[/span][span style=\"color:#007700\"]=[/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"SELECT * FROM Profiles WHERE `Email` = \'$username\'\"[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
[/span][span style=\"color:#0000BB\"]?>
[/span]
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

this will kill the script and give you the error if it's the query that's causing the problem.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 -Felix-

-Felix-
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 06 October 2005 - 01:50 PM

ok, it reports

Unknown column 'abcd' in 'where clause'


abcd is the username Im using.

But I dont get this...I have only one profile in this database because Im testing, I have made sure many times that there really is the correct username, in the correct field. ???

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2005 - 01:57 PM

ok, it reports

abcd is the username Im using.

But I dont get this...I have only one profile in this database because Im testing, I have made sure many times that there really is the correct username, in the correct field. ???

View Post


that's because of the quotes. you've got to have strings offset by quotes in a where clause. look carefully at my last post. i offset the column name with tics, and i offset the $username with single quotes. that will get rid of the "unknown column" error
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users