Jump to content

Weird MySQL error


GB_001

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/81005-weird-mysql-error/
Share on other sites

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';

Link to comment
https://forums.phpfreaks.com/topic/81005-weird-mysql-error/#findComment-411121
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.