MySQL Forums
Forum List  »  PHP

Need help with php variables in MySQL Query
Posted by: Ryan Shast
Date: July 20, 2008 12:46AM

I am trying to make a query that will create a table based on a person's user id, and then insert data into that table using variables. I have tried many combinations and searched for hours on google trying to figure out what I am doing wrong.

here is a query I wrote to create the table:
$maketable = 'CREATE TABLE `' . $user . '` (name CHAR(30))';
mysql_query( $maketable );

That makes the table, with the name of the user's ID for the table title and a column called 'name'.

But when I use the query below, it does nothing and gives me an error:
$addinfo = "INSERT INTO `" . $user . "` (name) VALUES ('" . $name . "')";
mysql_query( $addinfo ) or die(mysql_error());

Please note that I have tried around a hundred variations. it outputs the error:
unknown column 'name' in 'field list' or something similar.
I created the 'name' column along with the table, but it's not recognizing it. People said they fixed it by putting ' ' around the string in the Values, but I already tried that. Anybody have a workaround to this or are able to fix the query I wrote so I could get this to work?

If you need any information or anything please let me know. People also said that they fixed the problem by rebooting their MySQL client, but mine is located on my webhost's server, so I don't know of anyway to reboot that?

And sorry if I don't understand some of the things you might tell me or if I didn't make it clear enough; I'm new at this and am only 14 so bear with me =)

Thanks in advance!

Options: ReplyQuote


Subject
Written By
Posted
Need help with php variables in MySQL Query
July 20, 2008 12:46AM
July 20, 2008 09:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.