need help some noob problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

need help some noob problems

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: need help some noob problems

Post 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.
User avatar
azycraze
Forum Commoner
Posts: 56
Joined: Mon Oct 24, 2011 12:08 pm
Location: India

Re: need help some noob problems

Post 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.
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

Re: need help some noob problems

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: need help some noob problems

Post 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);
red wolf
Forum Newbie
Posts: 11
Joined: Sun Feb 19, 2012 4:38 am

Re: need help some noob problems

Post by red wolf »

i am so stupid!
thank you so much dear friends!
Post Reply