Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

Insert data into mssql database

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: macek, egami, gesf

Insert data into mssql database

Postby dashwood75 » Thu May 19, 2005 6:17 am

I am having problems inserting data into a mssql database,

I have the connection working fine as I can read and output data ok, but when I am trying to insert data using a form I get the following error:

Fatal error: Call to undefined function mssql_query() in D:\Apache2\htdocs\processcall.php on line 13

if possible can someone help me with the code!! :?

Code: Select all
<?
require_once('./odbccon.php');
$name = $_POST['requestor'];
$tsk = $_POST['task'];
$dsc = $_POST['description'];

$insert = "Insert into tasks (REQUEST,TASK,DESCRIPT) values ('$name','$tsk','$dsc')";

mssql_query($insert) or die('Unable to log call');
?>
User avatar
dashwood75
New php-forum User
New php-forum User
 
Posts: 10
Joined: Tue Nov 30, 2004 12:38 pm
Location: Blighty

Re: Insert data into mssql database

Postby WiZARD » Thu May 19, 2005 9:51 pm

dashwood75 wrote:I am having problems inserting data into a mssql database,

I have the connection working fine as I can read and output data ok, but when I am trying to insert data using a form I get the following error:

Fatal error: Call to undefined function mssql_query() in D:\Apache2\htdocs\processcall.php on line 13

if possible can someone help me with the code!! :?

Code: Select all
<?
require_once('./odbccon.php');
$name = $_POST['requestor'];
$tsk = $_POST['task'];
$dsc = $_POST['description'];

$insert = "Insert into tasks (REQUEST,TASK,DESCRIPT) values ('$name','$tsk','$dsc')";

mssql_query($insert) or die('Unable to log call');
?>

be sure what MS SQL library is ON (php.ini). By default all additional library is disabled.
Code: Select all
<?php
phpinfo();
?

see inside.
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby dashwood75 » Fri May 20, 2005 2:51 am

I have enabled the mssql libraries, which I should have realised as I had to enable the mysql ones when I setup my php install!!

but alas I am still having problems.

the error code has changed to this:

Warning: mssql_query(): supplied resource is not a valid MS SQL-Link resource in D:\Apache2\htdocs\processcall.php on line 15

this is the line it is referencing:

Code: Select all
<?
mssql_query($insert,$connectionstring)or die('Unable to log call');
>?


the $insert is my sql statement, and the $connectionstring is my connection information.

if anyone can help correct my code it is appreciated!!

:help:
User avatar
dashwood75
New php-forum User
New php-forum User
 
Posts: 10
Joined: Tue Nov 30, 2004 12:38 pm
Location: Blighty

Postby WiZARD » Fri May 20, 2005 3:07 am

dashwood75 wrote:I have enabled the mssql libraries, which I should have realised as I had to enable the mysql ones when I setup my php install!!

but alas I am still having problems.

the error code has changed to this:

Warning: mssql_query(): supplied resource is not a valid MS SQL-Link resource in D:\Apache2\htdocs\processcall.php on line 15

this is the line it is referencing:

Code: Select all
<?
mssql_query($insert,$connectionstring)or die('Unable to log call');
>?


the $insert is my sql statement, and the $connectionstring is my connection information.

if anyone can help correct my code it is appreciated!!

:help:

This error tell you what somthing incorrect.

be sure what:
1) connection is present
2) query is correct
3) query return true

If you are trying put info in table what not exist see 2
are you sure what your tables is uppercased?

try table field put in quotes like:
$insert = "insert into tasks (`REQUEST`,`TASK`,`DESCRIPT`) values (`$name`,`$tsk`,`$dsc`)";
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby ruturajv » Sun May 22, 2005 12:12 am

be sure you specify the port as well 1433 when connecting the DB
Code: Select all
<?php
$conn = mssql_connect('server,1433', 'username', 'password'); // If your OS(web server) is windows
$conn = mssql_connect('server:1433', 'username', 'password'); // If your OS(web server) is linux
?>
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby dashwood75 » Wed May 25, 2005 5:11 am

Cheers for the advice, but in the end opted to do it a different way by using form to email submission, which now works a treat!

I am learning something finally!! :D
User avatar
dashwood75
New php-forum User
New php-forum User
 
Posts: 10
Joined: Tue Nov 30, 2004 12:38 pm
Location: Blighty

Postby Alexej Kubarev » Fri May 27, 2005 10:05 am

Hehe.. good job :) by the way -- i do not agree with your signature ;)
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron