-Felix- Posted October 6, 2005 Share Posted October 6, 2005 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 Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/ Share on other sites More sharing options...
obsidian Posted October 6, 2005 Share Posted October 6, 2005 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--] Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/#findComment-8688 Share on other sites More sharing options...
-Felix- Posted October 6, 2005 Author Share Posted October 6, 2005 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? Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/#findComment-8689 Share on other sites More sharing options...
obsidian Posted October 6, 2005 Share Posted October 6, 2005 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. Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/#findComment-8690 Share on other sites More sharing options...
-Felix- Posted October 6, 2005 Author Share Posted October 6, 2005 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. ??? Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/#findComment-8691 Share on other sites More sharing options...
obsidian Posted October 6, 2005 Share Posted October 6, 2005 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 Quote Link to comment https://forums.phpfreaks.com/topic/2621-whats-wrong-with-this/#findComment-8692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.