473,387 Members | 1,504 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,387 software developers and data experts.

Delete Script

Hi everyone,

I appreciate all of your help with me and the problems I have been
having. I'm new to PHP and MySQL and I'm having some problems getting
this script to work. I can't get this to work and I don't understand
why. I don't get an error or anything, it almost seems like the page
refreshes. I went to the phpmyadmin and the row is still in the
database. The $_GET parts work perfectly in another script and the SQL
statement works when I insert hard values in it. Any thoughts would be
greatly appreciated. Thanks in advance.

<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>

<?php

function process_form() {

// Access the global variable $db inside this function
global $db;

$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];

if ($_POST['yes_no'] == 'yes') {

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
\'$artist_name\' AND album_title = \'$album_title\'";
// Delete the record
$db->query($delete_sql);
print "The record was deleted";
} else {
print "The record was not deleted";
}
}

?>

Aug 11 '06 #1
17 1724
mp*****@gmail.com wrote:
Hi everyone,

I appreciate all of your help with me and the problems I have been
having. I'm new to PHP and MySQL and I'm having some problems getting
this script to work. I can't get this to work and I don't understand
why. I don't get an error or anything, it almost seems like the page
refreshes. I went to the phpmyadmin and the row is still in the
database. The $_GET parts work perfectly in another script and the SQL
statement works when I insert hard values in it. Any thoughts would be
greatly appreciated. Thanks in advance.
<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];
The form method is POST, then
$_GET['isbn']=$_GET['artist_name']=$_GET['album_title']=NULL
use $_POST['isbn'], $_POST['artist_name'] and $_POST['album_title'].

You can simplify your form tag, action="" is the same as calling itself, less
code and less work for PHP if you use:

<form method="POST" action="">

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
\'$artist_name\' AND album_title = \'$album_title\'";
$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
'$artist_name' AND album_title = '$album_title'";

Remember that the column isbn has to be INT.

//Aho
Aug 11 '06 #2

J.O. Aho wrote:
mp*****@gmail.com wrote:
Hi everyone,

I appreciate all of your help with me and the problems I have been
having. I'm new to PHP and MySQL and I'm having some problems getting
this script to work. I can't get this to work and I don't understand
why. I don't get an error or anything, it almost seems like the page
refreshes. I went to the phpmyadmin and the row is still in the
database. The $_GET parts work perfectly in another script and the SQL
statement works when I insert hard values in it. Any thoughts would be
greatly appreciated. Thanks in advance.

<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];

The form method is POST, then
$_GET['isbn']=$_GET['artist_name']=$_GET['album_title']=NULL
use $_POST['isbn'], $_POST['artist_name'] and $_POST['album_title'].

You can simplify your form tag, action="" is the same as calling itself, less
code and less work for PHP if you use:

<form method="POST" action="">

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
\'$artist_name\' AND album_title = \'$album_title\'";

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
'$artist_name' AND album_title = '$album_title'";

Remember that the column isbn has to be INT.

//Aho
Thanks! I should have mentioned that the following is required because
they are being pulled form the url
http://www.domain.com/delete_record....&album_title=:
$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];
I shouldn't use $_POST should I?

Thanks!

Aug 11 '06 #3
mpar612 wrote:
Thanks! I should have mentioned that the following is required because
they are being pulled form the url
http://www.domain.com/delete_record....&album_title=:
When looking at your example you don't provide this data at all and to make
things a lot easier I would include them into the form as hidden input-tags.
Things gets a lot easier if you keep on sending data in the same way and not
try to mix.
//Aho
Aug 11 '06 #4

J.O. Aho wrote:
mpar612 wrote:
Thanks! I should have mentioned that the following is required because
they are being pulled form the url
http://www.domain.com/delete_record....&album_title=:

When looking at your example you don't provide this data at all and to make
things a lot easier I would include them into the form as hidden input-tags.
Things gets a lot easier if you keep on sending data in the same way and not
try to mix.
//Aho
Thanks! Could you please elaborate a little bit more, I'm a beginner
and I don't really understand what you are saying. I don't see how I
am trying to mix the way that I am sending data.

Thanks!

Aug 12 '06 #5
mpar612 wrote:
J.O. Aho wrote:
>mpar612 wrote:
>>Thanks! I should have mentioned that the following is required because
they are being pulled form the url
http://www.domain.com/delete_record....&album_title=:
When looking at your example you don't provide this data at all and to make
things a lot easier I would include them into the form as hidden input-tags.
Things gets a lot easier if you keep on sending data in the same way and not
try to mix.
//Aho

Thanks! Could you please elaborate a little bit more, I'm a beginner
and I don't really understand what you are saying. I don't see how I
am trying to mix the way that I am sending data.

Thanks!
You claim you are trying to use data sent as POST and GET at the same time,
thats a try in mixing, in your example you don't send anything that could be
fetched with $_GET.
--- send all as post ---
<form method="POST" action="">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="isbn" value="<?PHP echo $isbn; ?>" />
<input type="hidden" name="artist_name" value="<?PHP echo $artist_name; ?>" />
<input type="hidden" name="album_title" value="<?PHP echo $album_title; ?>" />
<input type="hidden" name="_submit_check" value="1"/>
</form>
--- end of example ---

There you get all the data you needed to send, all sent as post.
//Aho
Aug 12 '06 #6
You need to start paying people here buddy. Or just give up on PHP SQL!!!
<mp*****@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
Hi everyone,

I appreciate all of your help with me and the problems I have been
having. I'm new to PHP and MySQL and I'm having some problems getting
this script to work. I can't get this to work and I don't understand
why. I don't get an error or anything, it almost seems like the page
refreshes. I went to the phpmyadmin and the row is still in the
database. The $_GET parts work perfectly in another script and the SQL
statement works when I insert hard values in it. Any thoughts would be
greatly appreciated. Thanks in advance.

<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>

<?php

function process_form() {

// Access the global variable $db inside this function
global $db;

$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];

if ($_POST['yes_no'] == 'yes') {

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
\'$artist_name\' AND album_title = \'$album_title\'";
// Delete the record
$db->query($delete_sql);
print "The record was deleted";
} else {
print "The record was not deleted";
}
}

?>

Aug 12 '06 #7
Webwasp wrote:
You need to start paying people here buddy. Or just give up on PHP SQL!!!
These are forums and responses are voluntary. If you don't want to
respond, then don't. Responding with comments like yours is not only
unnecessary, but also a waste of resources and everyone's time.

Aug 12 '06 #8
Webwasp schrieb:
You need to start paying people here buddy. Or just give up on PHP SQL!!!
Before teaching people how to behave in usenet you might want to learn
it yourself:
http://www.google.com/search?q=top-posting
http://www.google.com/search?q=netiquette

--
Markus
Aug 13 '06 #9

"Markus Ernst" <derernst@NO#SP#AMgmx.chwrote in message
news:44**********@news.cybercity.ch...
Webwasp schrieb:
>You need to start paying people here buddy. Or just give up on PHP SQL!!!

Before teaching people how to behave in usenet you might want to learn it
yourself:
I agree. The original question was so basic that it was obvious that the
writer had done no homework and didn't even know SQL. However, Markus'
reply was somewhat over the top. A simple, "You need to learn the basics of
SQL first. It is common to all relational databases. Google 'SQL tutorial'
online or pick up a book." would have been much more polite.

Shelly
Aug 13 '06 #10
Shelly schrieb:
"Markus Ernst" <derernst@NO#SP#AMgmx.chwrote in message
news:44**********@news.cybercity.ch...
>>Webwasp schrieb:
>>>You need to start paying people here buddy. Or just give up on PHP SQL!!!

Before teaching people how to behave in usenet you might want to learn it
yourself:


I agree. The original question was so basic that it was obvious that the
writer had done no homework and didn't even know SQL. However, Markus'
reply was somewhat over the top. A simple, "You need to learn the basics of
SQL first. It is common to all relational databases. Google 'SQL tutorial'
online or pick up a book." would have been much more polite.
I am sure you meant to say that Webwasps reply was somewhat over the
top? :-)

--
Markus
Aug 13 '06 #11

Markus Ernst wrote:
Shelly schrieb:
"Markus Ernst" <derernst@NO#SP#AMgmx.chwrote in message
news:44**********@news.cybercity.ch...
>Webwasp schrieb:

You need to start paying people here buddy. Or just give up on PHP SQL!!!

Before teaching people how to behave in usenet you might want to learn it
yourself:

I agree. The original question was so basic that it was obvious that the
writer had done no homework and didn't even know SQL. However, Markus'
reply was somewhat over the top. A simple, "You need to learn the basics of
SQL first. It is common to all relational databases. Google 'SQL tutorial'
online or pick up a book." would have been much more polite.

I am sure you meant to say that Webwasps reply was somewhat over the
top? :-)

--
Markus
Okay everyone, let's stop the bad talk and get down to business. This
is a forum where people go to for help if they are having problems. I
am new to PHP and MySQL and am trying to get a PHP and MySQL site
running. I have several books on the subject and I feel I have made
great progress in the last 5-6 weeks of working on this with little
programming background.

If you would like to help me, I would be very appreciative. If you
would not like to help, please keep your comments to yourself and not
respond. I am looking for any information that would be good. Whether
it be an explanation of what is wrong with my code or a link to a good
tutorial or even a suggestion to a good book.

For those who have tried to help me, thank you very much. I am very
appreciative and I say that in each of my responses. For those who
like to bash beginners, please keep your comments to yourself.

Now let's get back to what these groups are all about: Helping people
with PHP and SQL.

Thanks

Aug 13 '06 #12

J.O. Aho wrote:
mpar612 wrote:
J.O. Aho wrote:
mpar612 wrote:

Thanks! I should have mentioned that the following is required because
they are being pulled form the url
http://www.domain.com/delete_record....&album_title=:
When looking at your example you don't provide this data at all and to make
things a lot easier I would include them into the form as hidden input-tags.
Things gets a lot easier if you keep on sending data in the same way and not
try to mix.
//Aho
Thanks! Could you please elaborate a little bit more, I'm a beginner
and I don't really understand what you are saying. I don't see how I
am trying to mix the way that I am sending data.

Thanks!

You claim you are trying to use data sent as POST and GET at the same time,
thats a try in mixing, in your example you don't send anything that could be
fetched with $_GET.
--- send all as post ---
<form method="POST" action="">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="isbn" value="<?PHP echo $isbn; ?>" />
<input type="hidden" name="artist_name" value="<?PHP echo $artist_name; ?>" />
<input type="hidden" name="album_title" value="<?PHP echo $album_title; ?>" />
<input type="hidden" name="_submit_check" value="1"/>
</form>
--- end of example ---

There you get all the data you needed to send, all sent as post.
//Aho
Thanks, but I'm afraid that I don't understand why this needs to be
done. I have variables, $isbn = $_GET['isbn'], $artist_name =
$_GET['artist_name'] and $album_title = $_GET['album_title'] that are
pulling information from the url:
"www.domain.com/delete_record.php?isbn=1234567689&artist_name=&alb um_title=."

I want to run the delete query "DELETE FROM lounge WHERE isbn = $isbn
AND artist_name=\'$artist_name\' AND album_title=\'$album_title\'.

The $_GET values work when I do a print $isbn etc... The delete query
works in phpmyadmin when I specify hard values for isbn, artist_name
and album_title. For example the following query works: DELETE FROM
lounge WHERE isbn = 123456789.

These things will not work together and I'm not sure why. I believe it
is an issue with $isbn = $_GET['isbn'], $artist_name =
$_GET['artist_name'] and $album_title = $_GET['album_title'] and
inserting the variable names in the SQL query, but I'm not sure how
this works. My books don't cover this specific problem in detail.

Thank you very much for all of your help. I apologize if I'm asking
too many questions.

Aug 13 '06 #13
mpar612 schrieb:
>
Okay everyone, let's stop the bad talk and get down to business. This
is a forum where people go to for help if they are having problems. I
am new to PHP and MySQL and am trying to get a PHP and MySQL site
running. I have several books on the subject and I feel I have made
great progress in the last 5-6 weeks of working on this with little
programming background.

If you would like to help me, I would be very appreciative. If you
would not like to help, please keep your comments to yourself and not
respond. I am looking for any information that would be good. Whether
it be an explanation of what is wrong with my code or a link to a good
tutorial or even a suggestion to a good book.

For those who have tried to help me, thank you very much. I am very
appreciative and I say that in each of my responses. For those who
like to bash beginners, please keep your comments to yourself.

Now let's get back to what these groups are all about: Helping people
with PHP and SQL.

Thanks
1. This is not a support forum, but usenet. People are free to discuss
other people's postings in every aspect they consider as worth to be
discussed.

2. Shelly and me did not blame you, but blamed Webwasp for his/her
rudeness when blaming you.

3. You get very competent inputs by J.O. Aho in the other branch of this
thread. Feel free to ignore other branches like the one here, where the
discussion might not be helpful for you.

4. 4 days ago you started the thread "MySQL/PHP5 $_GET issue", where you
got competent help from J.O. Aho and myself. Instead of trying what J.O.
Aho suggested and provided the information necessary for tracking down
your problem, you decided to abandon this thread and start a new one.
This could be interpreted as a contradiction to your apologies and
assertions of appreciacion.

As far as I can see you got 2 pieces of advice you did not follow yet:
- echo the SQL query to see how it is actually sent to the database
- try to not mix GET and POST data
What prevents you from just trying it and reporting the results?

--
Markus
Aug 13 '06 #14
go fuck a piece of code you wrangled out of some!!
"mpar612" <mp*****@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Webwasp wrote:
>You need to start paying people here buddy. Or just give up on PHP SQL!!!

These are forums and responses are voluntary. If you don't want to
respond, then don't. Responding with comments like yours is not only
unnecessary, but also a waste of resources and everyone's time.

Aug 13 '06 #15
mpar612 wrote:
J.O. Aho wrote:
>>mpar612 wrote:
>>>J.O. Aho wrote:

mpar612 wrote:
>Thanks! I should have mentioned that the following is required because
>they are being pulled form the url
>http://www.domain.com/delete_record....&album_title=:

When looking at your example you don't provide this data at all and to make
things a lot easier I would include them into the form as hidden input-tags.
Things gets a lot easier if you keep on sending data in the same way and not
try to mix.
//Aho

Thanks! Could you please elaborate a little bit more, I'm a beginner
and I don't really understand what you are saying. I don't see how I
am trying to mix the way that I am sending data.

Thanks!

You claim you are trying to use data sent as POST and GET at the same time,
thats a try in mixing, in your example you don't send anything that could be
fetched with $_GET.
--- send all as post ---
<form method="POST" action="">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="isbn" value="<?PHP echo $isbn; ?>" />
<input type="hidden" name="artist_name" value="<?PHP echo $artist_name; ?>" />
<input type="hidden" name="album_title" value="<?PHP echo $album_title; ?>" />
<input type="hidden" name="_submit_check" value="1"/>
</form>
--- end of example ---

There you get all the data you needed to send, all sent as post.
//Aho


Thanks, but I'm afraid that I don't understand why this needs to be
done. I have variables, $isbn = $_GET['isbn'], $artist_name =
$_GET['artist_name'] and $album_title = $_GET['album_title'] that are
pulling information from the url:
"www.domain.com/delete_record.php?isbn=1234567689&artist_name=&alb um_title=."

I want to run the delete query "DELETE FROM lounge WHERE isbn = $isbn
AND artist_name=\'$artist_name\' AND album_title=\'$album_title\'.

The $_GET values work when I do a print $isbn etc... The delete query
works in phpmyadmin when I specify hard values for isbn, artist_name
and album_title. For example the following query works: DELETE FROM
lounge WHERE isbn = 123456789.

These things will not work together and I'm not sure why. I believe it
is an issue with $isbn = $_GET['isbn'], $artist_name =
$_GET['artist_name'] and $album_title = $_GET['album_title'] and
inserting the variable names in the SQL query, but I'm not sure how
this works. My books don't cover this specific problem in detail.

Thank you very much for all of your help. I apologize if I'm asking
too many questions.
As others have said - the problem is you're mixing GET and POST. You're
POSTing the form - but then trying to use GET to retrieve the values.

You can use one or the other - mixing both does not work well.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '06 #16
mpar612 wrote:
Webwasp wrote:
>>You need to start paying people here buddy. Or just give up on PHP SQL!!!


These are forums and responses are voluntary. If you don't want to
respond, then don't. Responding with comments like yours is not only
unnecessary, but also a waste of resources and everyone's time.
And when you keep asking basic questions without trying to find the
answer on your own, soon you'll stop getting responses to your questions.

We are not your personal consultants! I'd suggest you try a little more
on your own; you're quickly wearing out your welcome.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '06 #17

"J.O. Aho" <us**@example.netwrote in message
news:4k************@individual.net...
You can simplify your form tag, action="" is the same as calling itself,
less
code and less work for PHP if you use:

<form method="POST" action="">

I like that shortcut :-) but I'm not confident that it will always do as you
say.
at w3 html4 forms
http://www.w3.org/TR/html4/interact/...ml#adef-action
they say
action = uri [CT]
This attribute specifies a form processing agent. User agent behavior for a
value other than an HTTP URI is undefined.

So while it may work in some browsers I'm not confident that it always will.
Or have I missed something?

Thanks
Aug 23 '06 #18

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

Similar topics

5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
3
by: Asif Rahman | last post by:
Hi all! Please improve on the following code to make sure the record gets deleted only when the function returns false. Now I see the msgbox, but the record gets deleted no matter the user...
4
by: DrData | last post by:
I'm working on an ASP.Net application written in C#. On one page, there are several datagrid controls used to display, edit and delete detail records relating to the master record also displayed on...
0
by: Elton W | last post by:
Hi Peter, You use DeleteButton.Attributes.Add("onclick", "return confirm ('Are you sure you want to delete?');"); in datagrid_ItemDataBound event to add confirmation for delete button.
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...
5
by: rn5a | last post by:
The .NET 2.0 documentation states the following: When using a DataSet or DataTable in conjunction with a DataAdapter & a relational data source, use the Delete method of the DataRow to remove...
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. ...
5
by: paitoon | last post by:
I have a DHTML confirm box that i will use to confirm delete the information from my page which are from database.... this is the script </script> <script type="text/javascript"> function...
2
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line:...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.