Jump to content
xisto Community
Sign in to follow this  
Unstoppable

How To Connect Site To Database? [resolved]

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

That's not what I meant.

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

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.

Share this post


Link to post
Share on other sites

The code in conn.php:

<?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)

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.

Share this post


Link to post
Share on other sites

you trying to run this on Xisto 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. :) 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 :)). after this, you will be greeted with this: "Your SQL query has been executed successfully" which means you can then congratulate yourself. :(

 

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

Share this post


Link to post
Share on other sites

another thing is this: having your loginsystem.sql reside on the server itself will not be automagically recognized as your database. :) 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 :)). after this, you will be greeted with this: "Your SQL query has been executed successfully" which means you can then congratulate yourself. :(

 

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

Share this post


Link to post
Share on other sites

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


still agonizing with your database? you can DROP the whole database and start from scratch if need be. and to give you a walkthrough on databases, here is a guide on Mysql Database Setup:

http://forums.xisto.com/topic/6665-mysql-database-setup-setting-up-mysql-database-guide-to-use-mysql-database-in-your-site/

 

it's as plain as can be explained already with that, you just need to follow the steps correctly.

 

and next time you encounter any errors, kindly include the error (via a screenshot or a verbatim/word-for-word recap of the error) so we can better assist you with the problem.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.