4 Replies - 391 Views - Last Post: 10 November 2010 - 06:51 AM Rate Topic: -----

#1 althejandro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-June 10

create table trouble

Posted 09 November 2010 - 08:26 PM

I know I must be making an incredibly stupid error, but I'm trying to create a table with the name of a php variable


if i echo out $newTableName, it looks like it should, but for some reason it just isn't creating a table. I haven't had any other db problems so I know I have a good connection


function makeSourceTable($user, $source)
{
	 $omit = array('www.', 'com', 'net', 'org', 'edu', 'http', ':', 'rss', 'feeds.feedburner' ,
 	'.', '.com/', '//', '/news', '/index', 'xml', '/', 'content', 'feed', 'proxygoogle');
    	$cleanedFeed = str_replace($omit, "", $source);
		$finalFeed = ucfirst($cleanedFeed);
		$newTableName = $user.$finalFeed;
	mysql_query("CREATE TABLE `$newTableName`
	(
	aId INT AUTO_INCREMENT,
	PRIMARY KEY(aId),
	aName TEXT,
	aUrl TEXT,
	aAuthor TEXT,
	aDate TEXT,
	aContent TEXT,
	read TEXT,
	favorite TEXT,
	tag1 TEXT,
	tag2 TEXT,
	tag3 TEXT)");	
	}






Is This A Good Question/Topic? 0
  • +

Replies To: create table trouble

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2932
  • View blog
  • Posts: 10,134
  • Joined: 08-August 08

Re: create table trouble

Posted 09 November 2010 - 08:55 PM

Do this:

	mysql_query("CREATE TABLE `$newTableName`
	(
	aId INT AUTO_INCREMENT,
	PRIMARY KEY(aId),
	aName TEXT,
	aUrl TEXT,
	aAuthor TEXT,
	aDate TEXT,
	aContent TEXT,
	read TEXT,
	favorite TEXT,
	tag1 TEXT,
	tag2 TEXT,
	tag3 TEXT)") or die(mysql_error());	


What is the error?
Was This Post Helpful? 1
  • +
  • -

#3 althejandro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 29-June 10

Re: create table trouble

Posted 09 November 2010 - 09:13 PM

i'm getting

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 'read TEXT, favorite TEXT, tag1 TEXT, tag2 TEXT, tag3 TEXT)' at line 10

read must be a reserved word because I renamed it and it started working. thanks
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: create table trouble

Posted 10 November 2010 - 04:46 AM

Check out the list of MySQL Reserved Words. You shouldn't use read as a field name.
Was This Post Helpful? 1
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2932
  • View blog
  • Posts: 10,134
  • Joined: 08-August 08

Re: create table trouble

Posted 10 November 2010 - 06:51 AM

If you must use it, put back ticks around it: `read`
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1