Page 1 of 1

my sql questions

Posted: Thu Jan 27, 2005 9:27 pm
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?

Posted: Thu Jan 27, 2005 9:29 pm
by feyd
modify the query to:

Code: Select all

if(!mysql_query($query) or die(mysql_error())
that should shed some light.

Posted: Fri Jan 28, 2005 2:35 am
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

Posted: Fri Jan 28, 2005 4:25 pm
by crazyb8ss
so should my query look like this:
UPDATE UserData SET title1=$title1 WHERE userID=$userID
or what

Posted: Fri Jan 28, 2005 4:30 pm
by feyd
somewhat like that.. although you probably need to use some quoting..

Posted: Fri Jan 28, 2005 10:31 pm
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'");