2 Replies - 798 Views - Last Post: 30 July 2009 - 07:02 AM Rate Topic: -----

#1 fallen0ne09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 09

how to insert a value in a column with another value

Posted 30 July 2009 - 03:55 AM

i want to insert a value using mysql query but i cant seem to make it work... i tried where or be but it does not work here is my code could anyone help me.
<?php #MySQL-Insert-Into.php
# Copyright (c) 2007 by Dr. Herong Yang, http://www.herongyang.com/
#
  $con = mysql_connect("localhost", "root", "");
  $ok = mysql_select_db("shimm", $con);
  
  $msg = $_POST['description'];
  $date = date("Y-m-d");

  $sql = "INSERT INTO data (description) where pid desc limit 1 "
	 . " VALUES ('$description')";
  if (mysql_query($sql, $con)) {
	print("Saved");
	
  } else {
	print("Sending statement failed.\n");
	print(mysql_errno($con).": ".mysql_error($con)."\n"); 
  }
  
  mysql_close($con); 
?>
pid is my key... and i want to add some values in a column...
and this error keeps popping out.
Sending statement failed. 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where pid desc limit 1 VALUES ('')' at line 1  
could anyone help me i dont know what to do next... i really appreciate it..

Is This A Good Question/Topic? 0
  • +

Replies To: how to insert a value in a column with another value

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: how to insert a value in a column with another value

Posted 30 July 2009 - 04:31 AM

if you want to insert just pid and description use this query
INSERT INTO data (`pid`,`description`) values('$id','$description')

but try use Auto increment pid in you table and use this query
INSERT INTO data (`description`) values('$description')


if you want to update your query then use this query
UPDATE data SET `description`='$description' WHERE pid=$pid

Was This Post Helpful? 0
  • +
  • -

#3 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: how to insert a value in a column with another value

Posted 30 July 2009 - 07:02 AM

Don't forget to always enclose values with single quotes ;)

UPDATE data SET `description`='$description' WHERE pid='$pid'


This post has been edited by RPGonzo: 30 July 2009 - 07:04 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1