Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,576 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,879 people online right now. Registration is fast and FREE... Join Now!




MySQL Weird Error

 
Reply to this topicStart new topic

MySQL Weird Error, I hat0rz error

Limitation
1 Oct, 2008 - 07:32 AM
Post #1

New D.I.C Head
*

Joined: 27 Sep, 2008
Posts: 17


My Contributions
Hello dweds. As you know the code below creates a new database & tables. Well the codes did work, it created a database but not with the tables in it. Its kinda weird I tested the same codes but with different table names some hours ago and it worked, but now it does'nt.

I think theres something wrong with the table code which I cant figure out. I tried directly on SQL query and it shows the following error:
Error
SQL query:

mysql_select_db(
"game", $con
);

MySQL said:
#1064 - 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 'mysql_select_db("game", $con)' at line 1



Help would be appreciated alot. Thanks icon_up.gif


CODE
<?php

$con = mysql_connect("localhost","root","secret");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  
  
  }// Creates database
if (mysql_query("CREATE DATABASE game",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
  
//Creates tables in the database
mysql_select_db("game", $con);
$sql = "CREATE TABLE Users
(
usersID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(usersID),
Username varchar(32),
Password varchar(64),
Email varchar(64),
Gender ENUM('Male','Female'),
)";
mysql_query($sql,$con);
mysql_close($con);

?>

User is offlineProfile CardPM
+Quote Post

mocker
RE: MySQL Weird Error
1 Oct, 2008 - 07:40 AM
Post #2

D.I.C Regular
Group Icon

Joined: 14 Oct, 2007
Posts: 258



Thanked: 15 times
Dream Kudos: 25
My Contributions
You can't use that on the mysql command prompt because it is php code. The equivalent mysql command is 'use game'

With your CREATE TABLE command, remove the comma from the last "Gender ENUM('Male','Female')," line
User is offlineProfile CardPM
+Quote Post

Limitation
RE: MySQL Weird Error
1 Oct, 2008 - 07:48 AM
Post #3

New D.I.C Head
*

Joined: 27 Sep, 2008
Posts: 17


My Contributions
QUOTE(mocker @ 1 Oct, 2008 - 08:40 AM) *

You can't use that on the mysql command prompt because it is php code. The equivalent mysql command is 'use game'

With your CREATE TABLE command, remove the comma from the last "Gender ENUM('Male','Female')," line


Yeh I know I cant use it on SQL because its a php code, but what I used on SQL was:
mysql_select_db("game", $con);
$sql = "CREATE TABLE Users
(
usersID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(usersID),
Username varchar(32),
Password varchar(64),
Email varchar(64),
Gender ENUM('Male','Female')
)";


And yeh just noticed the ","
That ok?
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: MySQL Weird Error
1 Oct, 2008 - 07:50 AM
Post #4

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
The last comma in this line doesn't belong:
CODE
$sql = "CREATE TABLE Users (usersID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(usersID), Username varchar(32),
Password varchar(64), Email varchar(64), Gender ENUM('Male','Female'),)";


Change to:
CODE
$sql = "CREATE TABLE Users (usersID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(usersID), Username varchar(32),
Password varchar(64), Email varchar(64), Gender ENUM('Male','Female'))";


User is offlineProfile CardPM
+Quote Post

Limitation
RE: MySQL Weird Error
1 Oct, 2008 - 07:53 AM
Post #5

New D.I.C Head
*

Joined: 27 Sep, 2008
Posts: 17


My Contributions
Oh lol the error was just the comma ","
lol Im so dumb.
Cheers guys smile.gif
biggrin.gif
<33
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:08AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month