Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into MSSQL 2

Status
Not open for further replies.
Jan 28, 2003
18
US
I am new to PHP, and I am having trouble inserting information into a MSSQL table. I have searched the web and have found little information pertaining to PHP and MSSQL so I am asking for help again.

What I am doing is displaying queried page from the table and giving an option to insert more information into the table.
The insert is as follows:

Code:
<?php
//connect to a DSN "myDSN"

$conn = odbc_connect('DSN','reports','password');



if ($conn)
{

$query = "INSERT INTO dbo.PROD (comments, trx_dt, serial_no)
                 VALUES  ('this is a new comment', '10/21/2011 12:00:00AM', 880-1279)";

  odbc_close ($conn);
}
else echo "odbc not connected";

?>

I am looking to update the table with the information and return something saying that the record was updated.
Thanks in advance.

 
Your code does nothing of the sort. It merely assigns the query as a string to the $query variable and the simply closes the connection.

Take a read in PHP's online manual (the very bets source for function, help and examples) for odbc_prepare and odbc_execute.



Additionally you may want to use the mssql_ libraries if you don't want to connect through odbc, but rather through TCP


Then you can use the mssql_query and mssql_result functions to work with the queries any any data retrieved.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
You may also like to take a look at PDO

it is a framework(I think thats the correct description)
that works with multiple database engines making it easy to change databases without changing any of your main code, just the log on details (which should be kept in a seperate include file anyway).
 
Thanks vacunita and IPGURU, guess I will start doing some reading.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top