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, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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']); |
|
|||
|
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 |
|
|||
|
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??? |
|
|||
|
> $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 |
|
|||
|
"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()); |
|
|||
|
"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. |
|
|||
|
"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. |
|
|||
|
"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. |