Page 1 of 1

Can't insert in SQL SERVER 2000/7.0

Posted: Mon Jun 27, 2005 3:49 pm
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.

Posted: Mon Jun 27, 2005 4:37 pm
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

It's the same thing

Posted: Mon Jun 27, 2005 5:50 pm
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

Posted: Mon Jun 27, 2005 5:53 pm
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

No port specified

Posted: Tue Jun 28, 2005 9:44 am
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.

Posted: Tue Jun 28, 2005 10:16 am
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.

Posted: Tue Jun 28, 2005 10:50 am
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??

Posted: Mon Aug 08, 2005 9:14 am
by goremo
use this date format '2 jul, 2005'

Posted: Sat Sep 22, 2007 10:11 am
by JackV
Hi

What error message do you get?

Posted: Sat Sep 22, 2007 3:21 pm
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.

Posted: Sat Sep 22, 2007 4:08 pm
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.