6 Replies - 782 Views - Last Post: 17 December 2011 - 09:46 AM Rate Topic: -----

#1 co0l  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 18
  • Joined: 10-May 11

Wordpress, How do I insert the data in to current user's row...

Posted 16 December 2011 - 07:47 PM

Hello, I want to insert the data in to the database if the column is empty, if its not empty than i want to update that column. How do I make query for that.
I am using the Wordpress, please someone help me..
Thanks.

View Postco0l, on 16 December 2011 - 07:42 PM, said:

Hello, I want to insert the data in to the database if the column is empty, if its not empty than i want to update that column. How do I make query for that.
I am using the Wordpress, please someone help me..
Thanks.

He is what I have so far..
$wpdb->query(
	"
	INSERT $wpdb->postmeta 
	WHERE user_id = $current_user_id
	"
);

I know its not going to work, because this code i have is not even the right format.
so please any wordpress or mysql expert help me..

Is This A Good Question/Topic? 0
  • +

Replies To: Wordpress, How do I insert the data in to current user's row...

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Wordpress, How do I insert the data in to current user's row...

Posted 16 December 2011 - 08:38 PM

Hey,

If the column is empty you want perform an insert but if it is occupied you want to do an update? Basically to an UPDATE it doesn't matter whether or not a column is empty. UPDATE updates a row which means that only the row that is being updated has to exist.

Have a look at this example.
ID ---------- NAME ---------- AGE
0             codeprada       NULL


If I run a query like this
UPDATE `table` SET `AGE` = 150 WHERE `NAME` = 'codeprada'

it will run just fine even though the AGE column is empty.
Was This Post Helpful? 1
  • +
  • -

#3 co0l  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 18
  • Joined: 10-May 11

Re: Wordpress, How do I insert the data in to current user's row...

Posted 16 December 2011 - 08:44 PM

View Postcodeprada, on 16 December 2011 - 08:38 PM, said:

Hey,

If the column is empty you want perform an insert but if it is occupied you want to do an update? Basically to an UPDATE it doesn't matter whether or not a column is empty. UPDATE updates a row which means that only the row that is being updated has to exist.

Have a look at this example.
ID ---------- NAME ---------- AGE
0             codeprada       NULL


If I run a query like this
UPDATE `table` SET `AGE` = 150 WHERE `NAME` = 'codeprada'

it will run just fine even though the AGE column is empty.


Hey, Thanks for reply, I have one more question. How do I insert in to the row where id is equal to current user id?
how do I put that condition for insertion. please help me. thanks
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Wordpress, How do I insert the data in to current user's row...

Posted 16 December 2011 - 09:10 PM

Once the row exists you can't perform an insert with the exact same data because of constraints like the primary key and sometimes an unique key. You can only perform an update, delete or select on an existing row. Insert is used to create new rows.
Was This Post Helpful? 1
  • +
  • -

#5 co0l  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 18
  • Joined: 10-May 11

Re: Wordpress, How do I insert the data in to current user's row...

Posted 16 December 2011 - 09:59 PM

View Postcodeprada, on 16 December 2011 - 09:10 PM, said:

Once the row exists you can't perform an insert with the exact same data because of constraints like the primary key and sometimes an unique key. You can only perform an update, delete or select on an existing row. Insert is used to create new rows.


Hello, thanks 4 reply.
This is what i am trying to do.
there is already users table in wordpress database it it has several columns. I have added a 2 new column names "column_1" and "column_2".
Now I have created form for users to submit the data for those 2 column.
---------
Now I want to update the data for current logged in user in that two column when user click on submit.
Now I am trying to do from last 8 hours my eyes are about to pop out and still can't get it work. This is my first wordpress + PHP + Mysql self project.
so some one please help me and guide me through this.
Many many thanks in advance..please help..
Thanks.
Was This Post Helpful? -2
  • +
  • -

#6 calebjonasson  Icon User is offline

  • $bert = new DragonUnicorn(); $bert->rawr();
  • member icon

Reputation: 209
  • View blog
  • Posts: 989
  • Joined: 28-February 09

Re: Wordpress, How do I insert the data in to current user's row...

Posted 17 December 2011 - 01:07 AM

I don't know if you are a real person or just trolling.

If you want to update information for a logged in user you are going to have to perform an update on the row that holds the user information. Updates are a simple operation that should be done on a unique index. The index that you will be using is going to be based on the logged in users session.

http://www.w3schools...ysql_update.asp
Was This Post Helpful? 1
  • +
  • -

#7 co0l  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 18
  • Joined: 10-May 11

Re: Wordpress, How do I insert the data in to current user's row...

Posted 17 December 2011 - 09:46 AM

Hey thanks for reply I am not trolling..
I am new to all this php and mysql stuff, thats the only reason i sound like trolling!
but the link you gave me helped me a lot.
thanks again...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1