|
-
Jul 14th, 2008, 07:53 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] What is wrong with this?
I have the following code:
Code:
$query="";
$queryFile = fopen('create_tables.sql', "r") or exit("Unable to open file!");
while(!feof($queryFile))
{
$query = $query . fgets($queryFile);
}
fclose($queryFile);
$query = str_replace("\n",'',$query);
echo $query ."<br /><br /><br />";
$result = mysql_query($query);
echo $result;
mysql_close($conn);
inside the create_tables.sql file i have this:
Code:
CREATE TABLE UserTable(
InputID int not null auto_increment,
Element varchar(60),
Username varchar(60),
Password varchar(60),
Comment varchar,
primary key(InputID))
I'm new to PHP and MySQL, so i don't really know what's going wrong here. Apparently there doesn't need to be a semicolon at the end of this SQL statement?
I'm trying to create a table with those columns. You can see the primary key.
Database access is successful, just there's nothing being returned when that query is executed and no table is created in that database.
-
Jul 14th, 2008, 08:02 AM
#2
Re: What is wrong with this?
mysql_query returns resource if successful and FALSE if not. Assign the result of mysql_query to a variable and test this variable to see if it is false, then execute mysql_error to find out what caused the error.
PHP Code:
if ($result === FALSE) { echo(mysql_error()); }
-
Jul 14th, 2008, 08:17 AM
#3
Thread Starter
Fanatic Member
Re: What is wrong with this?
It said there was a problem near the primary key line, so i played around with it a bit and figured out that the error was being cause from varchar not having an argument.
I want this column to be able to have unlimited characters in it, so should i set it to 0?
Also on the w3schools website they don't have an argument in the varchar function (If i may call it that). http://www.w3schools.com/sql/sql_create.asp, i guessed that that made it have unlimited characters.
Edit:
Don't worry, after some research i discovered that changing varchar to text fixes the problem. Thanks for your help =D. I would rep you, but it says i already have.
Last edited by Slyke; Jul 14th, 2008 at 08:32 AM.
-
Jul 14th, 2008, 08:29 AM
#4
Re: What is wrong with this?
VARCHAR is a datatype. It cannot contain more than 256 character but if you want more you should use either TEXT or BLOB instead. These can grow up to 4GB in size.
-
Jul 14th, 2008, 08:33 AM
#5
Thread Starter
Fanatic Member
Re: What is wrong with this?
Yeah, just edited my previous post =D. Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|