GB_001 Posted December 10, 2007 Share Posted December 10, 2007 For some reason, I keep getting a MySQL error with this script. Please help. <?php session_start(); $MN=$_SESSION['email']; $PN=$_SESSION['password']; @mysql_connect("localhost", "gb_GB", "*********") or die(mysql_error()); @mysql_select_db("gb_USERInfo") or die(mysql_error()); $query="SELECT * FROM Ysers WHERE email = '$MN' AND Friend=0"; mysql_query($query)or die (mysql_error()); mysql_query("CREATE TABLE $MN(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), Friends VARCHAR(255), Pending INT, Relationship VARCHAR(255)")or die(mysql_error()); $query="UPDATE Ysers SET Friend='1' WHERE email='$MN' LIMIT 1"; mysql_query($query) or die(mysql_error()); mysql_close(); ?> Error: 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 '@hotmail.com(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), Friends VARCHAR(25' at line 1 Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 Why on earth are you attempting to create a new database table for each of your users in the first place? Quote Link to comment Share on other sites More sharing options...
kishan Posted December 10, 2007 Share Posted December 10, 2007 I think table name should be a valid one , will not take some special characters like &,@,# ....... Quote Link to comment Share on other sites More sharing options...
GB_001 Posted December 10, 2007 Author Share Posted December 10, 2007 Why on earth are you attempting to create a new database table for each of your users in the first place? It's basically a friendslist, with an id for each friend with Pending status and relationship for each user. Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 Much easier to do it in one table. CREATE TABLE freinds ( id INT NOT NULL AUTO_INCREMENT, user VARCHAR(80), friend VARCHAR(80), PRIMARY KEY(id) ); Then, say I had the friends bob, bill and mandy. INSERT INTO friends (user,friend) VALUES ('thorpe','bob'); INSERT INTO friends (user,friend) VALUES ('thorpe','bill'); INSERT INTO friends (user,friend) VALUES ('thorpe','mandy'); Now, to find all my friends.... SELECT friend FROM friends WHERE user = 'thorpe'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.