marts555 Posted June 4, 2009 Share Posted June 4, 2009 Hello! I'm kinda new to PHP so excuse me for bothering you all with such a newbie-like question and code... Well you'll understand what i want with this code so i wont bother you about explaining it but i wonder why do i get "mysql_fetch_array(): supplied argument is not a valid MySQL result resource" error when i try to open it with a browser. This is the code: <?php $d = date('Y.m.d'); echo $d; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("skolnieki",$con); $query="SELECT DISTINCT skolnieki WHERE date=$d"; $result=mysql_query($query,$con); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br>"; } ?> So can anyone explain what is wrong with this code since i don't see the problem but WAMP 2.0 says the error? ^^ And yes i've made sure that MySQL DB has the same date in it - "2009.06.04" i believe it is as text but then again i inserted it using MySQL consol from .txt file made in MExcel so i just guess it is as text. Just in case - there is a "name" column with a name XD Thanks, Marts555 Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 4, 2009 Share Posted June 4, 2009 That error means your query isn't valid. You're not telling it which table to select from. $query="SELECT DISTINCT skolnieki WHERE date=$d"; should be $query="SELECT DISTINCT skolnieki from YourTableName WHERE date=$d"; Quote Link to comment Share on other sites More sharing options...
marts555 Posted June 4, 2009 Author Share Posted June 4, 2009 Same error. But i tried to do this allso with "SELECT * FROM skolnieki WHERE date=$d" - should have the same effect but still same error Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 $query="SELECT * FROM skolnieki WHERE date='$d'"; Like that? Quote Link to comment Share on other sites More sharing options...
marts555 Posted June 4, 2009 Author Share Posted June 4, 2009 Thank you oh mighty gods of PHP ^^ I thot that $d was already a string so i didnt put the '' Thank you both for helping me! Quote Link to comment 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.