Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Closed TopicStart new topic
> How To Connect Site To Database? [resolved]
Unstoppable
post May 25 2007, 11:46 AM
Post #1


Member [Level 1]
****

Group: Members
Posts: 73
Joined: 18-May 07
Member No.: 43,278



I created a table in phpmyadmin, i copied the code in a file and uploaded this file onto the host. Now it says that it cannot connect to the database. The error lies within "mysql_select_db($db)" => so i think this means that it cant find the database? If anyone knows how to let my login and register forms connect to the database, please help me. I used a login system from this site, ill post the link later.
Go to the top of the page
 
+Quote Post
jlhaslip
post May 25 2007, 11:50 AM
Post #2


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



Got any code for us to look at?
Go to the top of the page
 
+Quote Post
Unstoppable
post May 25 2007, 12:23 PM
Post #3


Member [Level 1]
****

Group: Members
Posts: 73
Joined: 18-May 07
Member No.: 43,278



Here is the exact code i used (from the tutorial):
http://www.trap17.com/forums/complete-logi...stem-t7247.html
Go to the top of the page
 
+Quote Post
rvalkass
post May 25 2007, 12:24 PM
Post #4


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,056
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



Without seeing the code this is pretty hard to diagnose; it could be any one of hundreds of problems. However, check the basics: are your username and password correct? Is the database name correct? Is the server name correct?
Go to the top of the page
 
+Quote Post
jlhaslip
post May 25 2007, 12:52 PM
Post #5


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



That's not what I meant.

We need to see the "ACTUAL" code you are using.

QUOTE
i copied the code in a file


Did you change the Database Connection information in conn.php? for example????

There are several things which could be incorrect. We need to see the actual code you have copied and pasted, exactly as it exists on your account.
Go to the top of the page
 
+Quote Post
Unstoppable
post May 25 2007, 01:53 PM
Post #6


Member [Level 1]
****

Group: Members
Posts: 73
Joined: 18-May 07
Member No.: 43,278



The code in conn.php:

CODE
<?php
$host = 'localhost';
$user = '';
$pass = '';
$db = 'loginsystem';
mysql_connect($host,$user,$pass) or die ("Database is unavailable. Please try again later.1");
mysql_select_db($db) or die ("Database is unavailable. Please try again later.");
?>


I cut out my username and pass. I get the 2nd error message so my user and pass are right.

This is the code in the database file (loginsystem.sql)

CODE
CREATE TABLE `loginsystem` (
`FullName` VARCHAR( 50 ) NOT NULL ,
`Email` VARCHAR( 50 ) NOT NULL ,
`Age` VARCHAR( 2 ) NOT NULL ,
`Login` VARCHAR( 15 ) NOT NULL ,
`Password` VARCHAR( 15 ) NOT NULL
) ENGINE = MYISAM;


But im not sure about the method im using: on the phpmyadmin, when i created the table, i copied the code that was given. I pasted it into notepad and saved it as loginsystem.sql This file i uploaded to the directory where my site is.

Notice from serverph:
code tags added. please use appropriate bbcodes as needed.
Reason for edit: see moderator's note
Go to the top of the page
 
+Quote Post
Mermaid711
post May 25 2007, 02:04 PM
Post #7


Super Member
*********

Group: [HOSTED]
Posts: 377
Joined: 27-April 07
From: Texas!
Member No.: 42,252
Spam Patrol



i havent had this exact problem, b ut i have had problemd with connecting to the database
Go to the top of the page
 
+Quote Post
serverph
post May 25 2007, 05:37 PM
Post #8


Ancient Enigma
Group Icon

Group: [MODERATOR]
Posts: 1,753
Joined: 11-July 04
From: under the stars
Member No.: 76



you trying to run this on trap17 servers? you need to review your $db name. after you create a database with a name you assign (as you indicated in your case, loginsystem), your cpanel username is prefixed into that. hence, the proper db name the server will recognize, and which should appear in your configuration/settings file is something which looks like this: yourcpanelusername_loginsystem.

another thing is this: having your loginsystem.sql reside on the server itself will not be automagically recognized as your database. wink.gif go back to your phpmyadmin control panel, and select your loginsystem database from the dropdown menu (if you don't have your loginsystem db yet, click MySQL icon from cpanel first to create one). after selecting your database, click on the SQL tab, then copy and paste your SQL code (the one you have in your loginsystem.sql) on the form provided, then RUN it (press GO wink.gif). after this, you will be greeted with this: "Your SQL query has been executed successfully" which means you can then congratulate yourself. biggrin.gif

you can then proceed to test your script, and hopefully you can now connect successfully to your database.
Go to the top of the page
 
+Quote Post
Unstoppable
post May 25 2007, 07:15 PM
Post #9


Member [Level 1]
****

Group: Members
Posts: 73
Joined: 18-May 07
Member No.: 43,278



QUOTE(serverph @ May 25 2007, 07:37 PM) *
another thing is this: having your loginsystem.sql reside on the server itself will not be automagically recognized as your database. wink.gif go back to your phpmyadmin control panel, and select your loginsystem database from the dropdown menu (if you don't have your loginsystem db yet, click MySQL icon from cpanel first to create one). after selecting your database, click on the SQL tab, then copy and paste your SQL code (the one you have in your loginsystem.sql) on the form provided, then RUN it (press GO wink.gif). after this, you will be greeted with this: "Your SQL query has been executed successfully" which means you can then congratulate yourself. biggrin.gif

you can then proceed to test your script, and hopefully you can now connect successfully to your database.


Hmm, this isnt working, because I made the table in phpmyadmin which means that i get an error when i try to Run that query: this table already exists...

Can anyone please help me, feeling so desperate