Jump to content

whats wrong with this?


-Felix-

Recommended Posts

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

Link to comment
Share on other sites

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

303428[/snapback]

 

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--]

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

303435[/snapback]

 

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.

Link to comment
Share on other sites

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. ???

Link to comment
Share on other sites

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. ???

303447[/snapback]

 

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

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.