0

I am getting syntax error with the following statement

REPLACE INTO users (screenname, token, secret) VALUES( '$screenname', '$token', '$secret' ) WHERE 'screenname' = $screenname

The table has a primary key named id, which auto-increments.

1
  • I think can be an UPDATE statement Commented Oct 29, 2009 at 14:36

3 Answers 3

1

From what i know, REPLACE has no WHERE, you probably want UPDATE instead

Sign up to request clarification or add additional context in comments.

1 Comment

No need for a UPDATE IF EXISTS, running the query will only update the matching records. If none match nothing will get updated. You can try this out by copying the data you need into a temp table like this: (Use everything between the quotes) " CREATE TABLE test_table SELECT fields_you_need FROM table_name WHERE condition_you_need LIMIT x_amount" this is just a rough way to create some test data into a table so you can run your queries in a test environment and leave production/live table data alone. Cheers
0

You need to have a UNIQUE index on screenname.

Also your quotes are wrong in the WHERE clause:

WHERE screenname = '$screenname'

I'm going to assume all your variables have been put through mysql_real_escape_string() :)

2 Comments

If my id field is the primary key, how do i set the screenname field to unique? Im using phpmyadmin, and the option to set this is inactive.
Error SQL query: ALTER TABLE users DROP PRIMARY KEY , ADD PRIMARY KEY ( screenname ) MySQL said: Documentation #1170 - BLOB/TEXT column 'screenname' used in key specification without a key length
0

try removing both single quotes in the variables of the

values VALUES( '$screenname', '$token', '$secret' )

Eg:

values VALUES($screenname, $token, $secret )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.