Can't insert in SQL SERVER 2000/7.0

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fernando2005
Forum Newbie
Posts: 8
Joined: Tue May 31, 2005 3:04 pm
Location: Honduras

Can't insert in SQL SERVER 2000/7.0

Post by fernando2005 »

Hello everyone I'm having some problems with a page I developped in PHP.
I need to insert some records in a database that's located in a MSSQL SERVER 7.0, but everytime I try to make an insert in the database the code doesn't work, here's my code.

The file where the db conecction is configured is the following:

Code: Select all

<?
//db_config.inc.php
$servidor    = "172.17.1.67";
$usuario      = "sa";
$senha        = "sig2";
$banco        = "Cortes";
$conex = mssql_connect ($servidor,$usuario,$senha);
mssql_select_db ($banco, $conex);
?>
I'm trying to do this:

Code: Select all

<?
include "db_config.inc.php";
$sp = "insert into Fechas_cortes values ('2005-10-14')";
$a = mssql_query($sp,$conex);
?>
As I told you I can't insert any records although if I replace the insert for a select, the select is done ok. And I also have to add that if I access the SQL SErver using SQL Query Analizer from SQL SERVER 2000 I can do the inserts properly, so I guess that leaves out any permission problem.

Can anybody help? I can't migrate to a newer version of MSSQL SERVER b/c my app it's a secondary and I really need to make it work in that version.
Hope anyone can help.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

i dont think that it is diffrent for mssql but here is how it is done in mysql

Code: Select all

query = 'INSERT INTO table_name (row_name) VALUES ("2001-03-21")';
your missing the row name
fernando2005
Forum Newbie
Posts: 8
Joined: Tue May 31, 2005 3:04 pm
Location: Honduras

It's the same thing

Post by fernando2005 »

I know it's the same thing, probably it's my fault I forgot to mention that for this specific table there's only one field, so the syntax is ok. Besides that, I've tested it on a mssql server 2000 and it works fine, the problem is the database in the sql server 7.0
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

If i am not mistaken you will need to specify the port number when using mSsql

Code: Select all

$servidor    = "172.17.1.67:1433"; #i believe this is the default of mSsql
fernando2005
Forum Newbie
Posts: 8
Joined: Tue May 31, 2005 3:04 pm
Location: Honduras

No port specified

Post by fernando2005 »

Thanks for the reply but it's not necessary to specify the port in the server's address. In the server's address you can specify the IP of the server where SQL SERVER resides or you can also specify the name of the SQL SERVER's Instance.
I've tried it before in other databases and I've never required an IP., Besides that I, my problem isn't with the connection but wirh the specific insert that can't be done.
Hope you can help.
User avatar
cyberpac9
Forum Newbie
Posts: 10
Joined: Thu Jun 16, 2005 8:08 am

Post by cyberpac9 »

try this:

Code: Select all

//replaces single quotes ' with two single quotes '' because mssql does not use backslash as escape character.
function mssql_addslashes($data) {
   $data = str_replace("'", "''", $data);
   return $data;
}

$mydate = mssql_addslashes($mydate);
solved my problem when trying to insert and got errors with single quotes...i'm using mssql 2000.
fernando2005
Forum Newbie
Posts: 8
Joined: Tue May 31, 2005 3:04 pm
Location: Honduras

Post by fernando2005 »

Thanks cyberpac9, but the problem isn't entering a date field value, this was just as an example. I've tested it on other databases and that SQL Statement works fine. My issue is entering data in a SQL SERVER 7.0..I can't do it....what could be the problem??
goremo
Forum Newbie
Posts: 3
Joined: Sun Jun 26, 2005 3:35 am

Post by goremo »

use this date format '2 jul, 2005'
JackV
Forum Newbie
Posts: 6
Joined: Sat Sep 22, 2007 9:26 am

Post by JackV »

Hi

What error message do you get?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jack, this thread is two years old. If you don't stop waking up SERIOUSLY old threads I will be forced to take action against you. You don't want that, trust me.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

feyd wrote:Jack, this thread is two years old. If you don't stop waking up SERIOUSLY old threads I will be forced to take action against you. You don't want that, trust me.
Yes, I've already issued you two seperate warnings.. but since you choose to not read my private messages I will say this publically. We will take action against your account on the next infraction.
Post Reply