delete from database
am 01.03.2006 03:06:58 von Sheldon Glickler
I have code that does not delete from a database. The same code (cut an
paste in the same file, but different function and having a different query)
works. So, of course, I tested the query interactively. I echoed the query
and did a cut and paste when interactively connect to the database. That
one worked so it isn't the query since interactively it is seeing exactly
the same thing as the code produces.
Here is the code:
function deleteCatalog($catalog) {
$query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $Login);
...
}
The $query echos:
DELETE FROM CatalogNames WHERE sCatalogID='CMP'
As an example of code that works (in the same file)
function addToCatalog($cat_id, $cat_name) {
$query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
"VALUES ('" . $cat_id . "', '" . $cat_name . "')";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $_SESSION['Login']);
...
}
The second and third lines are identical (cut and pasted) as in other places
in the same code. In fact, it is only in this file that I do all the
database work. Every other function works. This is the only delete,
however.
Any ideas?
Shelly
Re: delete from database
am 01.03.2006 03:51:49 von Shion
Sheldon Glickler wrote:
> I have code that does not delete from a database. The same code (cut an
> paste in the same file, but different function and having a different query)
> works. So, of course, I tested the query interactively. I echoed the query
> and did a cut and paste when interactively connect to the database. That
> one worked so it isn't the query since interactively it is seeing exactly
> the same thing as the code produces.
> $result = mssql_query($query, $Login);
> $result = mssql_query($query, $_SESSION['Login']);
Looking at the query function in your two functions gives this main
difference. As deleteCatalog() hasn't the variable $Login assigned any value,
it will be the same as Null which isn't a valid resource link definer, either
you change the function to use the following line
$result = mssql_query($query);
or
$result = mssql_query($query, $_SESSION['Login']);
//Aho
Re: delete from database
am 01.03.2006 03:51:49 von Shion
Sheldon Glickler wrote:
> I have code that does not delete from a database. The same code (cut an
> paste in the same file, but different function and having a different query)
> works. So, of course, I tested the query interactively. I echoed the query
> and did a cut and paste when interactively connect to the database. That
> one worked so it isn't the query since interactively it is seeing exactly
> the same thing as the code produces.
> $result = mssql_query($query, $Login);
> $result = mssql_query($query, $_SESSION['Login']);
Looking at the query function in your two functions gives this main
difference. As deleteCatalog() hasn't the variable $Login assigned any value,
it will be the same as Null which isn't a valid resource link definer, either
you change the function to use the following line
$result = mssql_query($query);
or
$result = mssql_query($query, $_SESSION['Login']);
//Aho
Re: delete from database
am 01.03.2006 04:05:16 von Sheldon Glickler
"J.O. Aho" wrote in message
news:46kgi5Fbn0u2U1@individual.net...
>> $result = mssql_query($query, $Login);
>> $result = mssql_query($query, $_SESSION['Login']);
>
> Looking at the query function in your two functions gives this main
> difference. As deleteCatalog() hasn't the variable $Login assigned any
> value, it will be the same as Null which isn't a valid resource link
> definer, either you change the function to use the following line
Cut and paste error when writing this orogonal post. Here is the latest and
greatest for the two and the results are still that the delete doesn't work
and the insert does.
$query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $_SESSION['Login']);
$query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
"VALUES ('" . $cat_id . "', '" . $cat_name . "')";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $_SESSION['Login']);
Re: delete from database
am 01.03.2006 04:05:16 von Sheldon Glickler
"J.O. Aho" wrote in message
news:46kgi5Fbn0u2U1@individual.net...
>> $result = mssql_query($query, $Login);
>> $result = mssql_query($query, $_SESSION['Login']);
>
> Looking at the query function in your two functions gives this main
> difference. As deleteCatalog() hasn't the variable $Login assigned any
> value, it will be the same as Null which isn't a valid resource link
> definer, either you change the function to use the following line
Cut and paste error when writing this orogonal post. Here is the latest and
greatest for the two and the results are still that the delete doesn't work
and the insert does.
$query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $_SESSION['Login']);
$query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
"VALUES ('" . $cat_id . "', '" . $cat_name . "')";
mssql_select_db($database_Login, $_SESSION['Login']);
$result = mssql_query($query, $_SESSION['Login']);
Re: delete from database
am 01.03.2006 04:47:49 von Shion
Sheldon Glickler wrote:
> "J.O. Aho" wrote in message
> news:46kgi5Fbn0u2U1@individual.net...
>>> $result = mssql_query($query, $Login);
>>> $result = mssql_query($query, $_SESSION['Login']);
>> Looking at the query function in your two functions gives this main
>> difference. As deleteCatalog() hasn't the variable $Login assigned any
>> value, it will be the same as Null which isn't a valid resource link
>> definer, either you change the function to use the following line
>
> Cut and paste error when writing this orogonal post. Here is the latest and
> greatest for the two and the results are still that the delete doesn't work
> and the insert does.
Okey, then lets look at the $_SESSION['Login'], how do you set it and do you
really store that in a session and reuse it? How do you make the mssql_connect()?
//Aho
Re: delete from database
am 01.03.2006 04:47:49 von Shion
Sheldon Glickler wrote:
> "J.O. Aho" wrote in message
> news:46kgi5Fbn0u2U1@individual.net...
>>> $result = mssql_query($query, $Login);
>>> $result = mssql_query($query, $_SESSION['Login']);
>> Looking at the query function in your two functions gives this main
>> difference. As deleteCatalog() hasn't the variable $Login assigned any
>> value, it will be the same as Null which isn't a valid resource link
>> definer, either you change the function to use the following line
>
> Cut and paste error when writing this orogonal post. Here is the latest and
> greatest for the two and the results are still that the delete doesn't work
> and the insert does.
Okey, then lets look at the $_SESSION['Login'], how do you set it and do you
really store that in a session and reuse it? How do you make the mssql_connect()?
//Aho
Re: delete from database
am 01.03.2006 10:53:02 von Steve
On Tue, 28 Feb 2006 21:06:58 -0500, Sheldon Glickler wrote:
> I have code that does not delete from a database. The same code (cut an
> paste in the same file, but different function and having a different query)
> works. So, of course, I tested the query interactively. I echoed the query
> and did a cut and paste when interactively connect to the database. That
> one worked so it isn't the query since interactively it is seeing exactly
> the same thing as the code produces.
>
> Here is the code:
>
> function deleteCatalog($catalog) {
> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $Login);
> ...
> }
>
> The $query echos:
> DELETE FROM CatalogNames WHERE sCatalogID='CMP'
>
> As an example of code that works (in the same file)
> function addToCatalog($cat_id, $cat_name) {
> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
> ...
> }
>
>
> The second and third lines are identical (cut and pasted) as in other places
> in the same code. In fact, it is only in this file that I do all the
> database work. Every other function works. This is the only delete,
> however.
>
> Any ideas?
>
> Shelly
Some error handling *might* shed some light onto the problem???
Re: delete from database
am 01.03.2006 10:53:02 von Steve
On Tue, 28 Feb 2006 21:06:58 -0500, Sheldon Glickler wrote:
> I have code that does not delete from a database. The same code (cut an
> paste in the same file, but different function and having a different query)
> works. So, of course, I tested the query interactively. I echoed the query
> and did a cut and paste when interactively connect to the database. That
> one worked so it isn't the query since interactively it is seeing exactly
> the same thing as the code produces.
>
> Here is the code:
>
> function deleteCatalog($catalog) {
> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $Login);
> ...
> }
>
> The $query echos:
> DELETE FROM CatalogNames WHERE sCatalogID='CMP'
>
> As an example of code that works (in the same file)
> function addToCatalog($cat_id, $cat_name) {
> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
> ...
> }
>
>
> The second and third lines are identical (cut and pasted) as in other places
> in the same code. In fact, it is only in this file that I do all the
> database work. Every other function works. This is the only delete,
> however.
>
> Any ideas?
>
> Shelly
Some error handling *might* shed some light onto the problem???
Re: delete from database
am 01.03.2006 12:11:53 von Steve
> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
>
>
> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
I think it unlikely that you can reliably cache and reuse a database
resource between sessions. You should create a new session with each
invocation of the script.
---
Steve
Re: delete from database
am 01.03.2006 12:11:53 von Steve
> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
>
>
> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
> mssql_select_db($database_Login, $_SESSION['Login']);
> $result = mssql_query($query, $_SESSION['Login']);
I think it unlikely that you can reliably cache and reuse a database
resource between sessions. You should create a new session with each
invocation of the script.
---
Steve
Re: delete from database
am 01.03.2006 12:47:33 von Sheldon Glickler
"J.O. Aho" wrote in message
news:46kjr6Fbl4rbU1@individual.net...
> Sheldon Glickler wrote:
>> "J.O. Aho" wrote in message
>> news:46kgi5Fbn0u2U1@individual.net...
>>>> $result = mssql_query($query, $Login);
>>>> $result = mssql_query($query, $_SESSION['Login']);
>>> Looking at the query function in your two functions gives this main
>>> difference. As deleteCatalog() hasn't the variable $Login assigned any
>>> value, it will be the same as Null which isn't a valid resource link
>>> definer, either you change the function to use the following line
>>
>> Cut and paste error when writing this orogonal post. Here is the latest
>> and greatest for the two and the results are still that the delete
>> doesn't work and the insert does.
>
> Okey, then lets look at the $_SESSION['Login'], how do you set it and do
> you really store that in a session and reuse it? How do you make the
> mssql_connect()?
Yes, I do store it and it is there. It worked for all the others.
$hostname_Login = "localhost";
$database_Login = "the database name";
$username_Login = "the username";
$password_Login = "the password";
$apbLogin = mssql_pconnect($hostname_Login, $username_Login,
$password_Login) or die(mysql_error());
Re: delete from database
am 01.03.2006 12:47:33 von Sheldon Glickler
"J.O. Aho" wrote in message
news:46kjr6Fbl4rbU1@individual.net...
> Sheldon Glickler wrote:
>> "J.O. Aho" wrote in message
>> news:46kgi5Fbn0u2U1@individual.net...
>>>> $result = mssql_query($query, $Login);
>>>> $result = mssql_query($query, $_SESSION['Login']);
>>> Looking at the query function in your two functions gives this main
>>> difference. As deleteCatalog() hasn't the variable $Login assigned any
>>> value, it will be the same as Null which isn't a valid resource link
>>> definer, either you change the function to use the following line
>>
>> Cut and paste error when writing this orogonal post. Here is the latest
>> and greatest for the two and the results are still that the delete
>> doesn't work and the insert does.
>
> Okey, then lets look at the $_SESSION['Login'], how do you set it and do
> you really store that in a session and reuse it? How do you make the
> mssql_connect()?
Yes, I do store it and it is there. It worked for all the others.
$hostname_Login = "localhost";
$database_Login = "the database name";
$username_Login = "the username";
$password_Login = "the password";
$apbLogin = mssql_pconnect($hostname_Login, $username_Login,
$password_Login) or die(mysql_error());
Re: delete from database
am 01.03.2006 12:50:28 von Sheldon Glickler
"Steve" wrote in message
news:pan.2006.03.01.09.52.57.477061@Aint.Valid...
> On Tue, 28 Feb 2006 21:06:58 -0500, Sheldon Glickler wrote:
>
>> I have code that does not delete from a database. The same code (cut an
>> paste in the same file, but different function and having a different
>> query)
>> works. So, of course, I tested the query interactively. I echoed the
>> query
>> and did a cut and paste when interactively connect to the database. That
>> one worked so it isn't the query since interactively it is seeing exactly
>> the same thing as the code produces.
>>
>> Here is the code:
>>
>> function deleteCatalog($catalog) {
>> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog .
>> "'";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $Login);
>> ...
>> }
>>
>> The $query echos:
>> DELETE FROM CatalogNames WHERE sCatalogID='CMP'
>>
>> As an example of code that works (in the same file)
>> function addToCatalog($cat_id, $cat_name) {
>> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
>> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>> ...
>> }
>>
>>
>> The second and third lines are identical (cut and pasted) as in other
>> places
>> in the same code. In fact, it is only in this file that I do all the
>> database work. Every other function works. This is the only delete,
>> however.
>>
>> Any ideas?
>>
>> Shelly
>
> Some error handling *might* shed some light onto the problem???
I have an
if (!$result)
print the error including the query
That is how I got the query that I copied and used interactively
successfully. Everything before that looked fine.
Re: delete from database
am 01.03.2006 12:50:28 von Sheldon Glickler
"Steve" wrote in message
news:pan.2006.03.01.09.52.57.477061@Aint.Valid...
> On Tue, 28 Feb 2006 21:06:58 -0500, Sheldon Glickler wrote:
>
>> I have code that does not delete from a database. The same code (cut an
>> paste in the same file, but different function and having a different
>> query)
>> works. So, of course, I tested the query interactively. I echoed the
>> query
>> and did a cut and paste when interactively connect to the database. That
>> one worked so it isn't the query since interactively it is seeing exactly
>> the same thing as the code produces.
>>
>> Here is the code:
>>
>> function deleteCatalog($catalog) {
>> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog .
>> "'";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $Login);
>> ...
>> }
>>
>> The $query echos:
>> DELETE FROM CatalogNames WHERE sCatalogID='CMP'
>>
>> As an example of code that works (in the same file)
>> function addToCatalog($cat_id, $cat_name) {
>> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
>> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>> ...
>> }
>>
>>
>> The second and third lines are identical (cut and pasted) as in other
>> places
>> in the same code. In fact, it is only in this file that I do all the
>> database work. Every other function works. This is the only delete,
>> however.
>>
>> Any ideas?
>>
>> Shelly
>
> Some error handling *might* shed some light onto the problem???
I have an
if (!$result)
print the error including the query
That is how I got the query that I copied and used interactively
successfully. Everything before that looked fine.
Re: delete from database
am 01.03.2006 12:52:07 von Sheldon Glickler
"Steve" wrote in message
news:1141211513.214654.269950@z34g2000cwc.googlegroups.com.. .
>
>> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog .
>> "'";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>>
>>
>> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
>> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>
> I think it unlikely that you can reliably cache and reuse a database
> resource between sessions. You should create a new session with each
> invocation of the script.
This is one session where it works on one and fails on the other. I use a
mssql_pconnect, but I will try making a new connection.
Re: delete from database
am 01.03.2006 12:52:07 von Sheldon Glickler
"Steve" wrote in message
news:1141211513.214654.269950@z34g2000cwc.googlegroups.com.. .
>
>> $query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog .
>> "'";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>>
>>
>> $query = "INSERT INTO CatalogNames (sCatalogID, sCatalogName) " .
>> "VALUES ('" . $cat_id . "', '" . $cat_name . "')";
>> mssql_select_db($database_Login, $_SESSION['Login']);
>> $result = mssql_query($query, $_SESSION['Login']);
>
> I think it unlikely that you can reliably cache and reuse a database
> resource between sessions. You should create a new session with each
> invocation of the script.
This is one session where it works on one and fails on the other. I use a
mssql_pconnect, but I will try making a new connection.
Re: delete from database
am 01.03.2006 12:55:39 von Sheldon Glickler
"Sheldon Glickler" wrote in message
news:tOfNf.42241$X7.34902@bignews7.bellsouth.net...
> $hostname_Login = "localhost";
> $database_Login = "the database name";
> $username_Login = "the username";
> $password_Login = "the password";
> $apbLogin = mssql_pconnect($hostname_Login, $username_Login,
> $password_Login) or die(mysql_error());
cut and paste error. make that
> $Login = mssql_pconnect($hostname_Login, $username_Login,
I thought I changed removed all the apb's for the posting. Missed one The
original has it all there. I just wanted to make it as neutral as possible
for posting.
Re: delete from database
am 01.03.2006 12:55:39 von Sheldon Glickler
"Sheldon Glickler" wrote in message
news:tOfNf.42241$X7.34902@bignews7.bellsouth.net...
> $hostname_Login = "localhost";
> $database_Login = "the database name";
> $username_Login = "the username";
> $password_Login = "the password";
> $apbLogin = mssql_pconnect($hostname_Login, $username_Login,
> $password_Login) or die(mysql_error());
cut and paste error. make that
> $Login = mssql_pconnect($hostname_Login, $username_Login,
I thought I changed removed all the apb's for the posting. Missed one The
original has it all there. I just wanted to make it as neutral as possible
for posting.
Re: delete from database
am 01.03.2006 13:30:08 von Shion
Sheldon Glickler wrote:
> "J.O. Aho" wrote in message
It's really better if you do cut'n'paste the code as it is (of course for
security reasons not the login/password for your database) than modify it for
nice looking when you post, as you may manage to fix you problem when you edit
the code for posting and that way not will be able to detect the real problem.
>> Okey, then lets look at the $_SESSION['Login'], how do you set it and do
>> you really store that in a session and reuse it? How do you make the
>> mssql_connect()?
>
> Yes, I do store it and it is there. It worked for all the others.
>
> $hostname_Login = "localhost";
> $database_Login = "the database name";
> $username_Login = "the username";
> $password_Login = "the password";
> $Login = mssql_pconnect($hostname_Login, $username_Login,
> $password_Login) or die(mysql_error());
According to the code here you store the resource in $Login but in functions
you use $_SESSION['Login'], which is a reuse of a older resource which don't
have to be the same as current resource.
You should use the current one, there is always the risk that database has
closed the connection that the resource is pointing at, which makes things to
fail. You should use something like
$Login = mssql_pconnect($hostname_Login, $username_Login, $password_Login);
if(!$Login) {
echo "Theres is problem to connect with the database
\n";
exit;
}
die(mysql_error()) won't work for you, as you aren't using mysql, the closest
you can use would be die(mssql_get_last_message()) but the information from
mssql suxx quite a lot.
Use the $Login instead of the $_SESSION['Login'], this will most likely
require you to add the following line to your own functions
global $Login;
or add another parameter for your functions
function deleteCatalog($catalog,$sql_resource) {
$query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
mssql_select_db($database_Login, $sql_resource);
$result = mssql_query($query, $sql_resource);
...
}
//Aho
Re: delete from database
am 01.03.2006 13:30:08 von Shion
Sheldon Glickler wrote:
> "J.O. Aho" wrote in message
It's really better if you do cut'n'paste the code as it is (of course for
security reasons not the login/password for your database) than modify it for
nice looking when you post, as you may manage to fix you problem when you edit
the code for posting and that way not will be able to detect the real problem.
>> Okey, then lets look at the $_SESSION['Login'], how do you set it and do
>> you really store that in a session and reuse it? How do you make the
>> mssql_connect()?
>
> Yes, I do store it and it is there. It worked for all the others.
>
> $hostname_Login = "localhost";
> $database_Login = "the database name";
> $username_Login = "the username";
> $password_Login = "the password";
> $Login = mssql_pconnect($hostname_Login, $username_Login,
> $password_Login) or die(mysql_error());
According to the code here you store the resource in $Login but in functions
you use $_SESSION['Login'], which is a reuse of a older resource which don't
have to be the same as current resource.
You should use the current one, there is always the risk that database has
closed the connection that the resource is pointing at, which makes things to
fail. You should use something like
$Login = mssql_pconnect($hostname_Login, $username_Login, $password_Login);
if(!$Login) {
echo "Theres is problem to connect with the database
\n";
exit;
}
die(mysql_error()) won't work for you, as you aren't using mysql, the closest
you can use would be die(mssql_get_last_message()) but the information from
mssql suxx quite a lot.
Use the $Login instead of the $_SESSION['Login'], this will most likely
require you to add the following line to your own functions
global $Login;
or add another parameter for your functions
function deleteCatalog($catalog,$sql_resource) {
$query = "DELETE FROM CatalogNames WHERE sCatalogID='" . $catalog . "'";
mssql_select_db($database_Login, $sql_resource);
$result = mssql_query($query, $sql_resource);
...
}
//Aho
Re: delete from database
am 01.03.2006 14:18:13 von sheldonlg
Problem solved. I want to thank all for their help. The problem was
with the mssql_select_db in that the function did not know what the
$database_Login was. I changed my code to select the database first,
and then pass in the resource to the function.
Thanks again.
Re: delete from database
am 01.03.2006 14:18:13 von sheldonlg
Problem solved. I want to thank all for their help. The problem was
with the mssql_select_db in that the function did not know what the
$database_Login was. I changed my code to select the database first,
and then pass in the resource to the function.
Thanks again.