I have a db table created like this
CREATE TABLE products(id INT,
name varchar(32),
PRIMARY KEY(id,name),
quantity int,
avail varchar(5) );
If I use the following command on the command prompt, the value is inserted properly:
INSERT INTO products(name,quantity,avail) VALUES('stuffed bear doll',100,'OF_ST');
although the id is duplicated
but when I leave it inside the function like this
$query=sprintf("INSERT INTO products(name,quantity,avail) VALUES('%s',%d,'%s');",
$name,
$quan,
$avail);
mysql_query($query);
then there is no insertion done at all.
You needed to set auto_increment on the id field in your create table syntax. You can edit the column to add it.
Also, if $quan is not valid your SQL syntax will give you an error. Put quotes around it:
VALUES('%s','%d','%s')