0

Hello everyone,

I would like to know how to create a PHP file to create the following database:

Database name: "dbUsers."

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username varchar(16) Unique
password char(16) 
email varchar(25)

Thanks :)

Edited by Aser Gado: n/a

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by luweegee
0

Hello everyone,

I would like to know how to create a PHP file to create the following database:

Database name: "dbUsers."

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username varchar(16) Unique
password char(16) 
email varchar(25)

Thanks :)

I Would think that something like the following would do the trick, although I would expand the size of the email address. I always use 254 because you never know how long someone's address could be.

$create="CREATE TABLE dbUsers (
id int(10) NOT NULL AUTO INCREMENT,
username VARCHAR( 16 ) NOT NULL ,
password CHAR( 16 ) NOT NULL ,
email VARCHAR( 25 ) NOT NULL ,
PRIMARY KEY ( id )
UNIQUE KEY username (username)
)
";
$table=mysql_query($create);

Hope this helps
Douglas

0

Didnt work its said "Can't create the table 'dbUsers' in the database.

Query was empty"

here is the full code I used

<?php

mysql_connect ('fdb2.eu.pn', '566608_mlsc', 'asdasd') ;
mysql_select_db ('566608_mlsc');

$create="CREATE TABLE dbUsers (
id int(10) NOT NULL AUTO INCREMENT,
username VARCHAR( 16 ) NOT NULL ,
password CHAR( 16 ) NOT NULL ,
email VARCHAR( 25 ) NOT NULL ,
PRIMARY KEY ( id )
UNIQUE KEY username (username)
)
";
$table=mysql_query($create);

$result = mysql_query($sql) or print("Can't create the table 'dbUsers' in the database.<br />" . $sql . "<br />" . mysql_error());

if ($result != false) {
    echo "Table 'dbUsers' was successfully created.";
}

mysql_close();

?>
0

What is the purpose of line 17?

$result = ....

And where does the $sql come from?

look in your database to see if the table was actually created with the first query

$table=mysql_query($create);

that should have created the table. Then when you tried to recreate the table with the second query, it found that it already existed and couldn't re-create it.

My best guess

you could eliminate line 17 and change line 19 to read

if ($table != false) {

to get the desired results...

But that is only if the table doesn't already exist.

Douglas

0

are u sure this code is working? how do you put this variable $sql if u did not defined?

$result = mysql_query($sql) or print("Can't create the table 'dbUsers' in the database.<br />" . $sql . "<br />" . mysql_error());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.