Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL query works first time, but not second. 1

Status
Not open for further replies.

wraygun

Programmer
Dec 9, 2001
272
US
Hi there,

I have an INSERT query that fires based on whether or not a user is logged in. The first query in the script works propery and adds the user to the table 'users' each time I log in with a new user. The second table 'profiles' only allows 1 entry, so if I drop all the records in the table, and log in with 'userXYZ' it will make that entry into the table. If I log in with another user 'userABC' it won't make the entry. This works the first time no matter who I log in with. The first table 'users' allows me to continue adding users (making a new record each time a new user logs in). I'm probably missing something simple, but I would greatly appreciate some assistance.

Code:
include ('config.php');
include ('opendb.php');
if ($un == "Anonymous") {

} else {

mysql_query("INSERT INTO users (username,state,jobtitle,uscitizen,yearsofexperience) 
VALUES ('$un','not specified','not specified','not specified','not specified')");

mysql_query("INSERT INTO profiles (username,nickname,height,weight,hair,eyes,location,age,hobbies,relationshipstatus,favoritemusic,education,work,favoritefood,dislikedfood,favoritetvshows,dislikedtvshows,favoritemovies,dislikedmovies,favoritevideogames,stuffyoudislike,favoritewebsites,favoriteseasons,backgroundcolor,sidebarcolor,backgroundtiled,backgroundpicture) 
VALUES ('$un','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified','Not Specified')");
}

Best regards,
Harold

***You can't change your past, but you can change your future***
 
Could there be a unique index on one of the columns other than username? Can you show us a "SHOW CREATE TABLE" output?
 
Tony,

That was brilliant. Thanks, and have a star. I inadvertently marked the 'nickname' as unique instead of 'username'. Changing that fixed everything. I really appreciate it.

Best regards,
Harold

***You can't change your past, but you can change your future***
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top