6 Replies - 920 Views - Last Post: 10 May 2011 - 09:04 AM Rate Topic: -----

#1 carmelraj  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 50
  • Joined: 28-April 11

Updating in PHP/MySQL

Posted 10 May 2011 - 05:06 AM

$sql="INSERT INTO order_details(co_id,company_name,bookingf_no,amount,discount,amount_payable,amount_collected,balance_payable_on,balance_payed,executive,receipt_no,receipt_date,no_of_iss,add_size,remarks)VALUES('$id','$_POST[company_name]','$_POST[bookingf_no]','$_POST[amount]','$_POST[discount]','$_POST[amount_payable]','$_POST[amount_collected]','$_POST[balance_payable_on]','$_POST[balance_payed]','$_SESSION[User]','$_POST[receipt_no]','$_POST[receipt_date]','$_POST[no_of_issues]','$_POST[size]','$_POST[remarks]') ON DUPLICATE KEY UPDATE order_id=LAST_INSERT_ID(order_id)";



I am trying to update the values which is already available in mysql databases.If not it will insert new values. Insertion is working but UPDATING THE EXISTING VALUES IS NOT WORKING.please help me

Is This A Good Question/Topic? 0
  • +

Replies To: Updating in PHP/MySQL

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3524
  • View blog
  • Posts: 10,169
  • Joined: 08-June 10

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 05:17 AM

for updating already existing datasets use the UPDATE statement.
Was This Post Helpful? 0
  • +
  • -

#3 carmelraj  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 50
  • Joined: 28-April 11

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 05:33 AM

i don't how to update it... i try to use LAST_INSERT_ID() but its not working...
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 06:03 AM

Perhaps you are looking for the 'ON DUPLICATE KEY' operation.
check here:
http://dev.mysql.com...-duplicate.html
Was This Post Helpful? 0
  • +
  • -

#5 carmelraj  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 50
  • Joined: 28-April 11

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 06:06 AM

id=LAST_INSERT_ID(id)


this is not working do u know why.....
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3524
  • View blog
  • Posts: 10,169
  • Joined: 08-June 10

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 07:08 AM

it depends on the statement, but I guess you’re using it wrong.

about LAST_INSERT_ID(expr):

The MySQL Manual said:

If expr is given as an argument to LAST_INSERT_ID(), the value of the argument is returned by the function and is remembered as the next value to be returned by LAST_INSERT_ID().


see also LAST_INSERT_ID() @ MySQL

This post has been edited by Dormilich: 10 May 2011 - 07:09 AM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Updating in PHP/MySQL

Posted 10 May 2011 - 09:04 AM

Why do people not want to spend any time LEARNING the language in which they're writing and READING the documentation? Geez.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1