help with my first learning database

This is a discussion on "help with my first learning database" within the Databases section. This forum, and the thread "help with my first learning database are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Mar 15th, 2007, 18:55
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Cool help with my first learning database

Is there something wrong with these?

Code: Select all
CREATE TABLE personnel
(
id int NOT NULL AUTO_INCREMENT,
firstname varchar(25),
lastname varchar(20),
nick varchar(12),
email varchar(35),
salary int,
PRIMARY KEY (id),
UNIQUE id (id)
);
INSERT INTO personnel VALUES ('1','John','Lever','John', 'john@everywhere.net','75000');
INSERT INTO personnel VALUES ('2','Camilla','Anderson','Rose', 'rose@flower.com','66000');
I put the following codes in php and...

Code: Select all
<HTML>
<?php
$db = mysql_connect("localhost", "root", "");
mysql_select_db("learndb",$db);
$result = mysql_query("SELECT * FROM personnel",$db);
echo "<TABLE>";
echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>";
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>";
echo $myrow["firstname"];
echo " ";
echo $myrow["lastname"];
echo "<TD>";
echo $myrow["nick"];
echo "<TD>";
echo $myrow["salary"];
}
echo "</TABLE>";
?>
</HTML>
...this is what I get


Warning: mysql_connect(): Access denied for user: 'root@localhost' (Using password: NO) in /home/(location)/index.php on line 10

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/(location)/index.php on line 11

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/(location)/index.php on line 12

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/(location)/index.php on line 15
Full NameNick NameSalary



Please someone help me

Last edited by geyids; Mar 16th, 2007 at 14:17.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Mar 16th, 2007, 07:08
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

You haven't given your MySQL password (for the MySQL account called root) as the third parameter to mysql_connect, so you are being denied access to the database from withing the PHP. The other error messages are all the consequence of this failure.

You should probably use a different account to the root one to access your database, and you it's advisable to apply passowrds to all the MySQL accounts that you have.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Mar 16th, 2007, 13:13
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Im not root in the webserver im uploading my database to. if u dont mind pliz help me where im I supposed to put my password in this
Code: Select all
CREATE TABLE personnel
(
id int NOT NULL AUTO_INCREMENT,
firstname varchar(25),
lastname varchar(20),
nick varchar(12),
email varchar(35),
salary int,
PRIMARY KEY (id),
UNIQUE id (id)
);
INSERT INTO personnel VALUES ('1','John','Lever','John', 'john@everywhere.net','75000');
INSERT INTO personnel VALUES ('2','Camilla','Anderson','Rose', 'rose@flower.com','66000');
or im I supposed to put in the php one?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Mar 16th, 2007, 13:29
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

In the php

Code: Select all
$db = mysql_connect("localhost", "root", "password goes here");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Mar 16th, 2007, 14:27
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

OK i changed this line to

Code: Select all
$db = mysql_connect("localhost", "myusername", "mypassword");
and this is what I got...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/(mylocation)/index.php on line 15
Full NameNick NameSalary

Did I make a mistake to replace "root" with my username? im not root in the server

Last edited by geyids; Mar 16th, 2007 at 15:43.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Mar 16th, 2007, 14:30
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Ok ... could you repost updated php please ... and tell us which is line 15
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Mar 16th, 2007, 15:41
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

PHP: Select all


<?php
$db 
mysql_connect("localhost""myusername""mypassword");
mysql_select_db("learndb",$db);
$result mysql_query("SELECT * FROM personnel",$db);
echo 
"<TABLE>";
echo
"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>";
while (
$myrow mysql_fetch_array($result))
{
echo 
"<TR><TD>";
echo 
$myrow["firstname"];
echo 
" ";
echo 
$myrow["lastname"];
echo 
"<TD>";
echo 
$myrow["nick"];
echo 
"<TD>";
echo 
$myrow["salary"];
}
echo 
"</TABLE>";
?>
line 15 is...

PHP: Select all

while ($myrow mysql_fetch_array($result)) 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Mar 16th, 2007, 15:49
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Remove ,$db from you mysql_query .... I'm pretty sure you don't need that.

And this
PHP: Select all

echo"<TR><TD><B>Full Name</B><TD><B>Nick Name</B><TD><B>Salary</B></TR>"
should be
PHP: Select all

echo"<TR><TD><B>Full Name</B></TD><TD><B>Nick Name</B></TD><TD><B>Salary</B></TD></TR>"
Don't forget to close your tags ... you need to fix it in the while ( ) section too.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Mar 16th, 2007, 17:38
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

what do I have to "fix it in the while ( ) section too" sorry im a learner in both php and mysql. I've looked at the line and saw I dont have a ";" is that right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Mar 16th, 2007, 17:44
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Quote:
Originally Posted by geyids View Post
what do I have to "fix it in the while ( ) section too" sorry im a learner in both php and mysql.
closing the </td> properly.

Quote:
Originally Posted by geyids View Post
I've looked at the line and saw I dont have a ";" is that right?
no ... a while loop doesn't have ; it's

Code: Select all
while (expression) {
 statement
}
http://ca3.php.net/manual/en/control...ures.while.php

Did you try what I suggested?!?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Mar 16th, 2007, 17:46
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

This is the codes I have at present but they still aint working the error is the same...

PHP: Select all

<?php
$db 
mysql_connect("localhost""myusername""mypassword");
mysql_select_db("learndb",$db);
$result mysql_query("SELECT * FROM personnel",$db);
echo 
"<TABLE>";
echo
"<TR><TD><B>Full Name</B></TD><TD><B>Nick Name</B></TD><TD><B>Salary</B></TD></TR>";
while (
$myrow mysql_fetch_array($result));
{
echo 
"<TR><TD>";
echo 
$myrow["firstname"];
echo 
" ";
echo 
$myrow["lastname"];
echo 
"<TD>";
echo 
$myrow["nick"];
echo 
"<TD>";
echo 
$myrow["salary"];
}
echo 
"</TABLE>";
?>

...this is the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/(mylocation)/index.php on line 15
Full NameNick NameSalary
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Mar 16th, 2007, 17:48
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Did you try this!

Quote:
Originally Posted by karinne View Post
Remove ,$db from you mysql_query .... I'm pretty sure you don't need that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Mar 16th, 2007, 17:49
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

ok wait will check on it then tell you thnx hope u r not tired with this silly learner
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Mar 16th, 2007, 17:51
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

Quote:
Originally Posted by geyids View Post
ok wait will check on it then tell you thnx hope u r not tired with this silly learner
I'm a fairly patient woman but I wish you would read the whole reply
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Mar 16th, 2007, 18:37
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

I removed the
PHP: Select all

$db 

but doesn't help. What is wrong with this
PHP: Select all

mysql_fetch_array() 

in...
PHP: Select all

while ($myrow mysql_fetch_array($result)) 

is there no other alternative on this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Mar 17th, 2007, 18:20
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 20
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

I got the solution. I asked the guy who opened the account for me and he told me the error was the db created was not called learndb but...! So I changed it and its working now. Thanx anyway for ur help i've learned alot
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Mar 17th, 2007, 21:57
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with my first learning database

good stuff!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!