Forum Moderators: open

Message Too Old, No Replies

MSSQL not inserting data.

It doesn't even give me an error message (PHP)

         

apg88

5:31 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



I'm writing a PHP script that saves a form data into a MSSQL database.
Here is the code that is not working:

$query = "INSERT INTO dbo.focus_ideas (id,name, email, idea, date) VALUES (0,'$_POST[name]','$_POST[email]','$_POST[idea]', " . mktime() . ")";
$tmp =mssql_query($query);

I haven't worked with MSSQL before, I can't find a function similar to mysql_error() to tell me what exactly is going bad.
Any ideas?

Thank you,

Alvaro

stajer

7:43 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



I don't know php but to me it looks like the problem is you are entered a "0" in the ID field. If that field is an IDENTITY field, you can't enter a value - mssql will automatically enter an ID for you.

syber

8:13 pm on Oct 18, 2006 (gmt 0)

10+ Year Member



To expand on the above, if the ID column creates its value automatically with the IDENTITY property - ignore it completely in the INSERT statement.

$query = "INSERT INTO dbo.focus_ideas (name, email, idea, date) VALUES ('$_POST[name]','$_POST[email]','$_POST[idea]', " . mktime() . ")";
$tmp =mssql_query($query);