The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


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: , , , ,

Closed Thread
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 08-03-2007, 10:02 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Icon13 [SOLVED] Database Connection PHP Still Doesn't Work, Please Help!!!

Here's all the code that I have and some screen shot that I have the database from phpMyAdmin:

admin/index.php
PHP Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Login</title>
</head>
<body>
<?php
include 'config.php';
?>
<form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="get">
<!-- not yet implemented -->
</form>
</body>
</html>
admin/config.php
PHP Code:
<?php
$username 
'username';         // MySQL username
$password 'password';         // MySQL password
$host 'localhost';        // MySQL host

$db 'webtest';            // Database name

$link mysql_connect($host,$username,$password) or die(mysql_error());

mysql_select_db($db);        // Select database

// MySQL Query
$query 'CREATE TABLE mycms ('.
         
'id INT NOT NULL AUTO_INCREMENT KEY'.
         
'username VARCHAR(10) NOT NULL, '.
         
'password VARCHAR(10) NOT NULL)'
         
$result mysql_query($query);
?>
webtest database from phpMyAdmin
*attached*
Attached Images
File Type: jpg phpmyadmin_problem1.jpg (46.5 KB, 2 views)

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #2 (permalink)  
Old 08-04-2007, 12:54 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
What's the error message? Let me encourage you again to never, never, never, never, never ever post for help with something without sharing the error message. Even if they seem totally unhelpful, they can point out things to a trained coder.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #3 (permalink)  
Old 08-04-2007, 01:15 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
Originally Posted by TeraTask View Post
What's the error message? Let me encourage you again to never, never, never, never, never ever post for help with something without sharing the error message. Even if they seem totally unhelpful, they can point out things to a trained coder.
LOL, that's because there's no error message...
If there's an error message, I could have Google it and say something about it
so it's basically just return me a blank page (since I didn't put anything on index.php)

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #4 (permalink)  
Old 08-04-2007, 01:18 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
OK. Well, that's important too! Run this and tell me what the output is:

PHP Code:
 <?php
$username 
'username';         // MySQL username
$password 'password';         // MySQL password
$host 'localhost';        // MySQL host

$db 'webtest';            // Database name

$link mysql_connect($host,$username,$password);
echo 
__line__.") ".mysql_error()."<br />";
mysql_select_db($db);        // Select database
 
echo __line__.") ".mysql_error()."<br />";
// MySQL Query
$query 'CREATE TABLE mycms ('.
         
'id INT NOT NULL AUTO_INCREMENT KEY'.
         
'username VARCHAR(10) NOT NULL, '.
         
'password VARCHAR(10) NOT NULL)'
         
$result mysql_query($query);
echo 
__line__.") ".mysql_error()."<br />";
?>
</div>

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
The Following User Says Thank You to TeraTask For This Useful Post:
HelloWorld (08-04-2007)
  #5 (permalink)  
Old 08-04-2007, 01:45 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
wow, that's really helpful.. thanx a lot TeraTask. but why doesn't it get detected with the the code that I had:

Code:
or die(mysql_error()
Here's the output:
Code:
 9) 
11) 
19) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEYusername VARCHAR(10) NOT NULL, password VARCHAR(10) NOT NULL)' at line 1

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by HelloWorld : 08-04-2007 at 01:51 AM.
  #6 (permalink)  
Old 08-04-2007, 01:52 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
It doesn't show up b/c the error is in your mysql_query statement, not in the connection. After each mysql_xxx() statement, you should check for an error. or die(); isn't a very friendly check either.

Try replacing the create table with this:
Code:
CREATE TABLE `mycms` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(10) NOT NULL,
  `password` varchar(10) NOT NULL,
  PRIMARY KEY  (`id`)
)

Also, take note that I have made the primary key primary and unsigned. These are good things for almost every primary key.

So, how did I get this code to generate the table? I created the table in phpmyadmin and then chose export the table structure - all the code perfectly generated for me with virtually no effort.

OK. Time for me to finally go to bed. gl!

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #7 (permalink)  
Old 08-04-2007, 01:59 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
For some reason the webtest database still doesn't show me any tables:

PHP Code:
// MySQL Query
$query 'CREATE TABLE mycms ('.
         
'id INT NOT NULL AUTO_INCREMENT KEY'.
         
'username VARCHAR(10) NOT NULL, '.
         
'password VARCHAR(10) NOT NULL, '.
         
'PRIMARY KEY  (id))'
that's what I got for the $query

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #8 (permalink)  
Old 08-04-2007, 02:33 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Look very closely at the code I put up there against your own code. You didn't copy-and-paste.

P.S. It's not necessary to break a string up into a bunch of pieces as you're doing. Just put single quotes around it and let it span as many lines as you want.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by Lee : 08-04-2007 at 03:19 AM. Reason: Please edit your last post!!! :)
The Following User Says Thank You to TeraTask For This Useful Post:
HelloWorld (08-04-2007)
  #9 (permalink)  
Old 08-04-2007, 08:16 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
Originally Posted by TeraTask View Post
Look very closely at the code I put up there against your own code. You didn't copy-and-paste.

P.S. It's not necessary to break a string up into a bunch of pieces as you're doing. Just put single quotes around it and let it span as many lines as you want.
Works beautiful, I shouldn't have cared about "." dots... I thought I'd have to put those to send queries from PHP lol... Thanx a lot TeraTask

PHP Code:
$query 'CREATE TABLE `mycms` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(10) NOT NULL,
  `password` varchar(10) NOT NULL,
  PRIMARY KEY  (`id`)
)'


__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
  #10 (permalink)  
Old 08-04-2007, 10:50 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Glad you got it. I've marked this as resolved.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Closed Thread


Thread Tools
Display Modes

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

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



All times are GMT -7. The time now is 12:41 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


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 44 45 46 47 48 49 50