473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
Mar 1 '06 #1
11 1698
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
Mar 1 '06 #2

"J.O. Aho" <us**@example.net> wrote in message
news:46************@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']);
Mar 1 '06 #3
Sheldon Glickler wrote:
"J.O. Aho" <us**@example.net> wrote in message
news:46************@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
Mar 1 '06 #4
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???

Mar 1 '06 #5
$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

Mar 1 '06 #6

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


Mar 1 '06 #7

"Steve" <Th*****@Aint.Valid> wrote in message
news:pa****************************@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.
Mar 1 '06 #8

"Steve" <go*********@nastysoft.com> wrote in message
news:11**********************@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.
Mar 1 '06 #9

"Sheldon Glickler" <sh*******@bellsouth.net> wrote in message
news:tO******************@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.
Mar 1 '06 #10
Sheldon Glickler wrote:
"J.O. Aho" <us**@example.net> 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<br>\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
Mar 1 '06 #11
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.

Mar 1 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: Bob Ganger | last post by:
Hello, I am working on a project using SQL Server 2000 with a database containing about 10 related tables with a lot of columns containing text. The total current size of the database is about...
7
by: Mike & Dyan | last post by:
I was able to figure out how to insert new data into my database. But for some reason and a lot of reading I can't seem to figure out how to delete any data. My app is going to be used for...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
3
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in...
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
10
by: pythonnoob | last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here. Before i post a question...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.