my sql questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazyb8ss
Forum Newbie
Posts: 11
Joined: Thu Jan 27, 2005 9:20 pm

my sql questions

Post by crazyb8ss »

I am attempting to make my own buddyprofile.com thing
i have a mySQL table thats set up with userID as the primary key and its increasing by 1 every time i add another user. Login and register both work. But when i try to add data to those tables later, i get really lost. My currenty code is set like this
$query = "REPLACE INTO UserData (userID, title1, text1) VALUES ('$userID', '$title1', '$text1')";
if(!mysql_query($query)) {
fail("Error inserting $userID, $title1, $text1");
}
where title 1 and text 1 would be the title and content for one of the profile pages. But i always get an error. Does anyone know what my code should look like, or is anyone interested in joining the project?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

modify the query to:

Code: Select all

if(!mysql_query($query) or die(mysql_error())
that should shed some light.
dakkonz
Forum Commoner
Posts: 69
Joined: Sat Dec 27, 2003 2:55 am
Location: Asia

Post by dakkonz »

Are u trying to insert additional data into ur table??? if so i think u shld be using UPDATE instead of REPLACE INTO. Replace will delete the current one and INSERT a new row.
see this on UPDATE :
http://dev.mysql.com/doc/mysql/en/update.html

try it see if it works
crazyb8ss
Forum Newbie
Posts: 11
Joined: Thu Jan 27, 2005 9:20 pm

Post by crazyb8ss »

so should my query look like this:
UPDATE UserData SET title1=$title1 WHERE userID=$userID
or what
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

somewhat like that.. although you probably need to use some quoting..
crazyb8ss
Forum Newbie
Posts: 11
Joined: Thu Jan 27, 2005 9:20 pm

Post by crazyb8ss »

for anyone who has this same problem, i solved it... Here is the code that WORKS

Code: Select all

mysql_query("UPDATE UserData SET title1='$title1', text1='$text1' WHERE userID='$userID'");
Post Reply