Hi, I have already create a db and populate it. I have already run some SQL queries and everything looks fine. Now when I am using PHP to connect to it and than retrieving data and displayign it, it's giving me above error. Here is the code config.php <?php // This is an example of config.php $dbhost = 'localhost'; $dbuser = 'test'; $dbpass = 'xyzxyz'; $dbname = 'files'; ?> Code (markup): opendb.php <?php // This is an example opendb.php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> Code (markup): select.php <?php include 'config.php'; include 'opendb.php'; $query = "SELECT * FROM games"; $result = mysql_query($query); echo "test"; [COLOR="Red"]while($row = mysql_fetch_array($result, MYSQL_ASSOC))[/COLOR] { echo "Name :{$row['author']} <br>"; } include 'closedb.php'; ?> Code (markup): the red line is where the problem is
try: while($row = mysql_fetch_assoc($result)) { echo "Name :{$row['author']} <br>"; } if that doesnt work its a prob with ure sql statement.
try using this "@mysql_fetch_array()" within your code. I had this issue when going to an upgraded PHP and had to add the "@" in.
That will just silence the error, it will not solve it. If you are getting that error it means there is a deeper problem, and the while loop will never run. So if you silence the error it will not achieve anything. P
are you pulling data from the POST or GET? You may have to specify where the data is being pulled from opposed to just using the variable name.
Ok guys, I have solved the problem. There was some problem with include files as well as with the database. Thanks to all of u for helping.Green reps to everyone
Hello, i'm still new with php & mysql. and i've got a little problem. i get the same error message, but i just couldn't find any solution to it. can anyone please tell me what to do? thanks! here's the code: <?php $con = mysql_connect("localhost","vikingas_post","kickass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("vikingas_website", $con); $result = mysql_query("SELECT * FROM vikingas_post"); [COLOR="Red"]while($row = mysql_fetch_array($result))[/COLOR] { echo "<hr>"; echo "<h3>"; echo $row['Date']; echo "</h3>"; echo "<br />"; echo "<br />"; echo $row['Post']; echo "<br />"; echo "<br />"; echo $row['Signature']; } mysql_close($con); ?> Code (markup): the problem is in the red line. thanks a lot!
umm ok... sorry about this. i've had a little typo in the code which i didn't notice. thanks for your help anyway! rep
sry this bump is needed. i have the same problem, its saying 'Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tamayi/public_html/index.php on line 17' the script: the ones in red is causing the problem, but i jus dont know whats wrong. please help me..
Hi I know this is a very old thread. I have replied that for the all future visitors with a view to helping them: see below: $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId"); Cart is table name here. I know that when table name is too short and without underscore thn mql shows the error. because mysql can not detect short name. when table name is too short and without underscore thn you must have to add ` both side of the table name in query. Or if u dont want to add ` thn select a name with a underscore or select a long name. See example and try below one and both will work : $result = mysql_query("select count(*) from `cart` where cookieId = '" . GetCartId() . "' and itemId = $itemId"); or, $result = mysql_query("select count(*) from cart_1 where cookieId = '" . GetCartId() . "' and itemId = $itemId");
I'm Also getting: PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Code: while ($row = call_user_func($func_name,$res_id)){ Any Suggestions?
Also getting: PHP Warning: Invalid argument supplied for foreach() Code:$r = DBquery($q); $out = array(); foreach ($r as $item) { $id = $item['id']; Any Suggestions?