Log in

View Full Version : Mysql fetch problems...



Rockonmetal
09-07-2008, 10:35 PM
I am having a lot of problems with Mysql and localhost. When I got my new computer I downloaded wampserver. Since it works I use it. Before on my old computer, I used netserver only because wamp wouldn't work. Though now I am having problems with MySQL.

Problem. When I try to get info via php from a database it gives me this error:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getaband.net\cp\index.php on line 39
Though I know my code is correct because when I made a test database called test with a table named table1 with two rows in there it showed both rows. But it refuses to show what I want it to show.
Comp info:
I am using windows vista, brand new computer
Database I want to access info:
Storage Engine: MyISAM
Collation: utf8_unicode_ci

I would have liked to test it on my site to see if it is a localhost problem but my site is down :(

Thanks for help...
Let me know if you need anything else...

allahverdi
09-08-2008, 10:14 AM
Can you show us all your code?

Rockonmetal
09-08-2008, 09:25 PM
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("users", $con);

$result = mysql_query("SELECT * FROM table3 WHERE id=1");
while($row = mysql_fetch_array($result))
{
echo "Welcome, " . $row['name'];
}
?>

There is the only php code on the page... the rest is illreverent html and css junk...

allahverdi
09-09-2008, 04:57 AM
Change this:

$result = mysql_query("SELECT * FROM table3 WHERE id=1");

To this:

$result = mysql_query("SELECT * FROM table3 WHERE id=1") or die(mysql_error());

When you will open your page there will be error(i think so). Different one. Then you will be able to fix that. If you couldn't paste that error here