![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: create, help, mysql, php, table |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| |||
| Try using the following: PHP Code: ![]() The "or die(mysql_error())" part simply says if mysql_query($query) returns FALSE (means there was an error), output whatever mysql_error() returns and then stop processing the page after that. Also, try this for your query: PHP Code: __________________ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." -- Bjarne Stroustrup, creator of what is now known as C++ For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that. |
| The Following User Says Thank You to rpgfan3233 For This Useful Post: | ||
HelloWorld (07-29-2007) | ||
| ||||
| Quote:
but it seems not working... probably I should give the full source code: admin/index.php PHP Code: PHP Code: |
| |||
| Did you try adding the die(mysql_error()) part to the line with $result like you have it on the line with $link ? What does it say if you tried that? __________________ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." -- Bjarne Stroustrup, creator of what is now known as C++ For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that. |
| |||
| Um, you're not selecting the database to use. Add this after the connection, but before your SQL: PHP Code: PHP Code: Last edited by molotov : 07-29-2007 at 11:48 PM. |
| ||||
| I just knew that you can SELECT a database, is that part of the SQL query? Because from what I know of, you need to have the table first before you can SELECT a table well, also called schema..? ![]() PHP Code: ![]() Last edited by HelloWorld : 07-29-2007 at 11:56 PM. |
| ||||
| OK. Here's how it goes, HelloWorld: 1) You have users. 2) You have databases. 3) You have tables. 1 user can have access to 0 or more databases. Each database can have 0 or more tables. You first connect to MySQL using your user. Since the user can access a number of databases, you must then tell MySQL which database you want to use (this user must have access to that database). After you have connected and indicated the database you can then perform operations on the selected database (such as creating a table). This type of setup has a nice advantage - users can have limited privileges on a database to protect the database from undesired changes by that user (root, for example, can do whatever it wants, but you don't want any ole user to be able to have that same power). |
| |||
| Let me try to epand on what TeraTask explained. Ok, you have a server oh which your website is kept and served to the internet. Your server has what are called dameon processes (or depending on your setup, 'services') that help it act like a web server. One of these dameons is the MySQL server. The MySQL dameon operates on the entire server, for all of it's users that have the correct privileges or are in the correct group. Now as you know, MySQL deals with databases - but a single MySQL dameon can handle LOTS of databases. You have to tell it which one to use! This is where mysql_select_db() comes in; it has nothing to do with your actual SQL statements except that it tells the MySQL daemon on which database to perform the statements. Ok, so you've got a server, with a MySQL daemon running and now you have your databases, when you connect to a database in PHP, you have to tell it the server to which you want to connect, the user* you are connecting as, as password for that user, and a database on the MySQL server that you want to use. Once you connect to the server and MySQL daemon and tell it which database to use, you can start sending it SQL statements and they will be executed on your database, and not someone else's. Any questions? ![]() *side note: You don't need to worry about this, but just for your information, there are two different 'types' or users here: OS users, and MySQL users. Presumably, your host has assigned you to the MySQL group, or given you the appropriate permissions. Once your OS-level user has permission to access the MySQL daemon, MySQL further requires authentication on a database-per-database level. |
| ||||
| Quote:
Quote:
|
| |||
| First of all, you have to have created a database in which to put a table. If you want to think of it in a hierarchy: Code: Internet V servers V databases V tables V fields V rows I drew up an AWESOME graphic for you ![]() ![]() If you're testing locally, you're just viewing your HOST file and skipping the internet step, and instead of a lot of servers, you only have one. Is that ANY clearer? |
| The Following 2 Users Say Thank You to molotov For This Useful Post: | ||
HelloWorld (07-30-2007), TeraTask (07-30-2007) | ||
![]() |
| Thread Tools | |
| Display Modes | |
| |