Creating a MySQL table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Creating a MySQL table

Post by Wldrumstcs »

Okay, I am at a loss. Where is the error?

Code: Select all

<?
include('connect.php');
$sql = mysql_query("CREATE TABLE users( user_id INT(11) NOT NULL AUTO_INCREMENT, username VARCHAR(255) NOT NULL FULL TEXT, password VARCHAR(32) DEFAULT 0 NOT NULL FULL TEXT, email VARCHAR(255) NOT NULL FULL TEXT, homepage VARCHAR(255) NOT NULL FULL TEXT, aim VARCHAR(100) NOT NULL FULL TEXT, date_format VARCHAR(50) NOT NULL FULL TEXT, date_join INT(11) DEFAULT 0 NOT NULL, post_last MEDINT(9) DEFAULT 0 NOT NULL, post_total MEDINT(9) DEFAULT 0 NOT NULL, PRIMARY KEY(user_id))");
echo 'Creating table: ''users''....';

?>
Last edited by Wldrumstcs on Tue Feb 15, 2005 4:06 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

want to at least say what mysql says?
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

I am highly confused by what you just wrote... Sorry.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

What. Is. The. MySQL. Error?
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

There is no visible error, the table just isn't created.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You never actually execute the command.

In PHP, when a variable is set to something, it isn't actually evaluated UNTIL it is referenced.
since $sql is never referenced, mysql_query never gets executed. Try just using it as a function instead of storing it as a variable.
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

What would the function look like?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

...

Post by s.dot »

PHPMyAdmin is a wonderful tool for creating and managing tables. It takes alot of the hassle out of creating it yourself.

Or in your example to execute the command, take the mysql_query( ); off of your $sql variable and then run mysql_query($sql);
Post Reply