Page 1 of 1

need help some noob problems

Posted: Sun Feb 19, 2012 4:43 am
by red wolf
so i open new db with only 1 table and 2 columns.
column : id + name
this is the php code i weite:

Code: Select all

<?php
$db = mysql_connect("localhost","alex_123","1234512345");
mysql_select_db("a", $db);
$result = mysql_query("select * from a", $db);
while($myrow = mysql_fetch_array($result));
{
    echo $myrow['name'];
}
?>
the problem:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/alex/public_html/index.php on line 10
line 10 is: while($myrow = mysql_fetch_array($result));
i try not writing this.
but this gave me the same results
what to do?

Re: need help some noob problems

Posted: Sun Feb 19, 2012 7:39 am
by Celauran
Start with var_dump($result) to see what type $result is. I'm guessing it will be boolean(false), which means your query is no good.

Re: need help some noob problems

Posted: Sun Feb 19, 2012 9:53 am
by azycraze
make sure that you have a table named as 'a'.
I noticed that your table name in following line

=======================================
$result = mysql_query("select * from a", $db);
========================================

is same as the database name.Make sure that you haven't written database name instead of table name.

Re: need help some noob problems

Posted: Sun Feb 19, 2012 11:31 pm
by red wolf
thanks for the fast reply
i try to add next one as you ask:

Code: Select all

<?php
$db = mysql_connect("localhost","alex_123","1234512345");
mysql_select_db("a", $db);

$result = mysql_query("select * from a", $db);
var_dump($result)
while($myrow = mysql_fetch_array($result));
{
    echo $myrow['name'];
}
?>
**the new result is :
Parse error: syntax error, unexpected T_WHILE in /home/alex/public_html/index.php on line 12
by the way maybe this is the problem:
my db name is : alex_test
SB user is : alex_test
table in the sql called: a
and in the table there is id (automatic) and name row.

Re: need help some noob problems

Posted: Mon Feb 20, 2012 4:46 am
by Celauran
You forgot the semicolon at the end of the var_dump line, hence the new error message. You say your database is called alex_test, yet you try to use a

Code: Select all

mysql_select_db("a", $db);

Re: need help some noob problems

Posted: Mon Feb 20, 2012 5:06 am
by red wolf
i am so stupid!
thank you so much dear friends!