Bluehost.com Web Hosting $6.95

delete from database

This is a discussion on delete from database within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have code that does not delete from a database. The same code (cut an paste in the same file, ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default delete from database

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


Reply With Quote
  #2 (permalink)  
Old 03-01-2006
J.O. Aho
 
Posts: n/a
Default Re: delete from database

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
Reply With Quote
  #3 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default Re: delete from database


"J.O. Aho" <user@example.net> 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']);


Reply With Quote
  #4 (permalink)  
Old 03-01-2006
J.O. Aho
 
Posts: n/a
Default Re: delete from database

Sheldon Glickler wrote:
> "J.O. Aho" <user@example.net> 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
Reply With Quote
  #5 (permalink)  
Old 03-01-2006
Steve
 
Posts: n/a
Default Re: delete from database

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???

Reply With Quote
  #6 (permalink)  
Old 03-01-2006
Steve
 
Posts: n/a
Default Re: delete from database


> $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

Reply With Quote
  #7 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default Re: delete from database


"J.O. Aho" <user@example.net> wrote in message
news:46kjr6Fbl4rbU1@individual.net...
> Sheldon Glickler wrote:
>> "J.O. Aho" <user@example.net> 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());




Reply With Quote
  #8 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default Re: delete from database


"Steve" <ThisOne@Aint.Valid> 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.


Reply With Quote
  #9 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default Re: delete from database


"Steve" <google.spam@nastysoft.com> wrote in message
news:1141211513.214654.269950@z34g2000cwc.googlegr oups.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.


Reply With Quote
  #10 (permalink)  
Old 03-01-2006
Sheldon Glickler
 
Posts: n/a
Default Re: delete from database


"Sheldon Glickler" <sheldonlg@bellsouth.net> 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.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:43 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0