dlbDennis Posted August 24, 2016 Share Posted August 24, 2016 $result=odbc_exec($strcon, $sql); //executing select * statement //need help from here down $count=odbc_fetch_array($result); if($count==1) //at least one row must exist { $rows=odbc_fetch_object($result); Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/ Share on other sites More sharing options...
NotionCommotion Posted August 24, 2016 Share Posted August 24, 2016 Try this. What does it display? I would expect it is a row of data, and not the count that you expected. $result=odbc_exec($strcon, $sql); //executing select * statement //need help from here down $count=odbc_fetch_array($result); var_dump($count); Try the following. It should get one row at a time. while($row=odbc_fetch_array($result)) { var_dump($row); } If you want to know how many rows you get, experiment with http://php.net/manual/en/function.odbc-num-rows.php. odbc_fetch_array() and odbc_fetch_object() are basically the same but one returns an array and the other returns.. wait for it... an object. There is no reason to do one, and then the other, but if you truly wanted both, I am sure their is a function for it. PS. I believe a PDO version for obdc exists, and you should definitely us it and use prepared statements. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536531 Share on other sites More sharing options...
dlbDennis Posted August 24, 2016 Author Share Posted August 24, 2016 $result=odbc_exec($strcon, $sql); $count=odbc_fetch_array($result); //var_dump($count); //This does dump the info on the record in the db if($count==1) while($row=odbc_fetch_array($result)) { // var_dump($row); //This does not get the data and tells me not found int db $pass = $rows['password']; //FETCHING PASS echo "your pass is ::".($pass)."" ; //DISPLAYING PASSWORD } else { Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536534 Share on other sites More sharing options...
Barand Posted August 24, 2016 Share Posted August 24, 2016 If you are expecting only one row then you already fetched it with $count=odbc_fetch_array($result); By the time you get to the while() loop there are no more left to fetch. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536538 Share on other sites More sharing options...
dlbDennis Posted August 27, 2016 Author Share Posted August 27, 2016 I'm still trying to get the password, username and email to populate at the bottom. $sql="SELECT * FROM $tbl_name WHERE email='$email'"; $result=odbc_exec($strcon, $sql); //executing select * statement //need help from here down $count=odbc_fetch_array($result); var_dump($count); //this does dump a row of data, but it looks like this. //array(5) { ["id"]=> string(1) "1" ["username"]=> string(3) "dlb" ["email"]=> string(20) "dlb@someemail.com" ["password"]=> string(5) "somepassword" ["active"]=> string(1) "1" } if($count==1) //at least one row must exist { $rows=odbc_fetch_array($count); $pass = $rows['password'];//FETCHING PASS echo "your pass is ::".($pass)."" ; echo "<br/>"; $username = $rows['username'];//FETCHING USERNAME echo "your username is ::".($username); echo "<br/>"; $email = $rows['email'];//FETCHING USERNAME echo "your email is ::".($email); } else { Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536754 Share on other sites More sharing options...
Barand Posted August 27, 2016 Share Posted August 27, 2016 You have been told what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536755 Share on other sites More sharing options...
dlbDennis Posted August 27, 2016 Author Share Posted August 27, 2016 I don't understand what I"m being told Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536756 Share on other sites More sharing options...
Barand Posted August 27, 2016 Share Posted August 27, 2016 Even though you can see the information that you want in the contents of that var_dump() after the first odbc_fetch_array($result) ? I'll - type- slowly - for - you - You - have - the - results - after - that - first - fetch. - After - that - there- are - no - more - records - left - to - fetch - so - the - results - of - the - next - fetch - are - empty. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536757 Share on other sites More sharing options...
Jacques1 Posted August 27, 2016 Share Posted August 27, 2016 You're calling odbc_fetch_array() twice, and each call is “destructive” in the sense that it removes the next row from the result set. When there's one row, only the first call gets it. The second call cannot fetch anything. How about you remove the first “test call” altogether and do your var_dump() when the data is actually supposed to be fetched? Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536758 Share on other sites More sharing options...
ginerjm Posted August 27, 2016 Share Posted August 27, 2016 IF you really must find out the number of results, have you tried odbc_num_rows function to see if it works with your driver? Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536759 Share on other sites More sharing options...
Jacques1 Posted August 27, 2016 Share Posted August 27, 2016 Frankly, I've never understood the purpose of those if-there's-a-row-then-fetch-it checks. I just call the fetch method. If it returns a row, I know there's one. If it doesn't, there's none (ignoring errors checks etc.). Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536760 Share on other sites More sharing options...
dlbDennis Posted August 27, 2016 Author Share Posted August 27, 2016 Even though you can see the information that you want in the contents of that var_dump() after the first odbc_fetch_array($result) ? I'll - type- slowly - for - you - You - have - the - results - after - that - first - fetch. - After - that - there- are - no - more - records - left - to - fetch - so - the - results - of - the - next - fetch - are - empty. Maybe it's pain from your age or who knows what. But if you read the rules. I joined this forum to try and understand php. I'm stuck using and access.mdb and need a password recovery script. I have searched the web and only find basic login scripts that use odbc_connect. I'm guessing no one wants to create a full script. But none of them have a password recovery script. So my options were to find one that works with mysql and try to modify it. I was understanding phpfreaks forum was for helping people like me understand php scripts. But I don't need flamed by a "Moderator" just because I don't understand. Thanks everyone for the help you have given and have a good weekend or whats left of it. Forum DO NOT'sDo not flame other users. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536762 Share on other sites More sharing options...
Jacques1 Posted August 28, 2016 Share Posted August 28, 2016 He “flamed” you? C'mon. You've had a mental block, and somebody made fun of it. Yes, that can happen on the Internet. So what? Your project is fine, being new to PHP is fine, and there are plenty of people willing to help you. Fix the problem and move on. When you don't understand something, it's generally a good idea to address it directly and ask specific questions. Ignoring replies or merely stating that you don't understand them isn't really helpful. It can also be frustrating after a while. 1 Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536774 Share on other sites More sharing options...
ginerjm Posted August 28, 2016 Share Posted August 28, 2016 OP - if you think Barand 'flamed' you you haven't seen anything yet. Barand is one of the MOST helpful on here so if he took the time to do what he did he is TRYING to tell you something but you aren't getting it. You were told twice to stop doing the extra (first) fetch and you didn't get it. Hard to "not understand" something that direct so I don't blame Barand for his last response. Neither should you. Quote Link to comment https://forums.phpfreaks.com/topic/301978-im-stuck-with-accessmdb-need-help-with-this-code/#findComment-1536786 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.