-2

I want to store my values to db. Also I want to upload one image. My insert query is below. It's not working.

$query = mysql_query("insert into designingoption set name='$name1',positionCode='$pos',assetType='$ass',price='$price',createdOn='$createdon',lastModifiedOn='$laston',lastModifiedBy='$lastby')",$con);

Here name=$name is my image upload field..

manoranjani
  • 11
  • 1
  • 8

3 Answers3

0

Not sure whats not working, but, i gotta a pretty good idea the values are not inserted since you used ' (single quote) around $variables.

Try like this.

 $query=mysql_query("insert into designingoption set name='".$name1."',positionCode='".$pos."',assetType='".$ass."',price='".$price."',createdOn='".$createdon."',lastModifiedOn='".$laston."',lastModifiedBy='".$lastby."')",$con);
sk8terboi87 ツ
  • 3,396
  • 3
  • 34
  • 45
0

You have mixed the syntax for the UPDATE and INSERT statements.

Correct syntax:

INSERT INTO designingoption ('name', 'positionCode', 'assetType', 'price', 'createdOn', 'lastModifiedOn', 'lastModifiedBy') VALUES ($pos, $ass, $price, $createdon, $laston, $lastby)

While you're at it, you might also want to consider switching to the mysqli-functions. The mysql-functions are deprecated.

Also be careful of SQL-injection. More information on the subject can be found here.

Community
  • 1
  • 1
Marty McVry
  • 2,838
  • 1
  • 17
  • 23
0

Update your query structure.

INSERT INTO designingoption (name,positionCode,assetType,price,createdOn,lastModifiedOn,lastModifiedBy) VALUES ('$name1','$pos','$ass','$price','$createdon','$laston','$lastby')

Also, make sure that all variables are populated, otherwise you get a PHP notice. It wouldn't hurt to enclose table rows with `, like this:

INSERT INTO `designingoption` (`name`,`positionCode`,`assetType`,`price`,`createdOn`,`lastModifiedOn`,`lastModifiedBy`) VALUES ('$name1','$pos','$ass','$price','$createdon','$laston','$lastby')

Some words are reserved by the system and must be used properly, otherwise you just receive error.

A little research as revealed (even to my surprise) that your syntax is correct. http://dev.mysql.com/doc/refman/5.5/en/insert.html

Would you please edit your question with exact error you're getting?

Kristjan O.
  • 814
  • 1
  • 9
  • 33