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.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 15th, 2007, 18:55
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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.
Reply With Quote

  #2 (permalink)  
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.
Reply With Quote
  #3 (permalink)  
Old Mar 16th, 2007, 13:13
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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?
Reply With Quote
  #4 (permalink)  
Old Mar 16th, 2007, 13:29
karinne's Avatar
SuperMember

SuperMember
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");
Reply With Quote
  #5 (permalink)  
Old Mar 16th, 2007, 14:27
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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.
Reply With Quote
  #6 (permalink)  
Old Mar 16th, 2007, 14:30
karinne's Avatar
SuperMember

SuperMember
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
Reply With Quote
  #7 (permalink)  
Old Mar 16th, 2007, 15:41
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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)) 

Reply With Quote
  #8 (permalink)  
Old Mar 16th, 2007, 15:49
karinne's Avatar
SuperMember

SuperMember
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.
Reply With Quote
  #9 (permalink)  
Old Mar 16th, 2007, 17:38
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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?
Reply With Quote
  #10 (permalink)  
Old Mar 16th, 2007, 17:44
karinne's Avatar
SuperMember

SuperMember
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?!?
Reply With Quote
  #11 (permalink)  
Old Mar 16th, 2007, 17:46
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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
Reply With Quote
  #12 (permalink)  
Old Mar 16th, 2007, 17:48
karinne's Avatar
SuperMember

SuperMember
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.
Reply With Quote
  #13 (permalink)  
Old Mar 16th, 2007, 17:49
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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
Reply With Quote
  #14 (permalink)  
Old Mar 16th, 2007, 17:51
karinne's Avatar
SuperMember

SuperMember
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
Reply With Quote
  #15 (permalink)  
Old Mar 16th, 2007, 18:37
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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?
Reply With Quote
  #16 (permalink)  
Old Mar 17th, 2007, 18:20
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to geyids Send a message via Yahoo to geyids Send a message via Skype™ to geyids
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
Reply With Quote
  #17 (permalink)  
Old Mar 17th, 2007, 21:57
karinne's Avatar
SuperMember

SuperMember
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!
Reply With Quote
Reply

Tags
first database

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning php! Monie PHP Forum 11 Oct 4th, 2007 13:39
CSS - Learning Freelancer Web Page Design 10 Nov 17th, 2006 14:30
XML Code for transfering data from one SQL Server Database to another database plolla Other Programming Languages 1 Aug 3rd, 2006 18:37
Learning PHP ecntrc PHP Forum 14 Nov 19th, 2005 05:05
Learning ASP.... courtjester Classic ASP 2 Feb 6th, 2004 00:38


All times are GMT. The time now is 19:49.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43