Home > Archive > PHP SQL > August 2006 > Delete Script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| mpar612@gmail.com 2006-08-11, 6:58 pm |
| 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";
}
}
?>
| |
| J.O. Aho 2006-08-11, 6:58 pm |
| mpar612@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
| |
| mpar612 2006-08-11, 6:58 pm |
|
J.O. Aho wrote:
> mpar612@gmail.com wrote:
>
>
>
> 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'";
>
> 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
www.domain.com/delete_record.php?is...e&album_title=:
> $isbn = $_GET['isbn'];
> $artist_name = $_GET['artist_name'];
> $album_title = $_GET['album_title'];
I shouldn't use $_POST should I?
Thanks!
| |
| J.O. Aho 2006-08-11, 6:58 pm |
| mpar612 wrote:
> Thanks! I should have mentioned that the following is required because
> they are being pulled form the url
> www.domain.com/delete_record.php?is...e&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
| |
| mpar612 2006-08-12, 7:57 am |
|
J.O. Aho wrote:
> mpar612 wrote:
>
>
> 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!
| |
| J.O. Aho 2006-08-12, 7:57 am |
| mpar612 wrote:
> J.O. Aho wrote:
>
> 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
| |
| Webwasp 2006-08-12, 7:57 am |
| You need to start paying people here buddy. Or just give up on PHP SQL!!!
<mpar612@gmail.com> wrote in message
news:1155327725.985414.159590@74g2000cwt.googlegroups.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";
> }
> }
>
> ?>
>
| |
| mpar612 2006-08-12, 6:58 pm |
| 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.
| |
|
|
| Shelly 2006-08-13, 6:58 pm |
|
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:44df318e$1_2@news.cybercity.ch...
> Webwasp schrieb:
>
> 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
| |
| Markus Ernst 2006-08-13, 6:58 pm |
| Shelly schrieb:
> "Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
> news:44df318e$1_2@news.cybercity.ch...
>
>
>
> 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
| |
| mpar612 2006-08-13, 6:58 pm |
|
Markus Ernst wrote:
> Shelly schrieb:
>
> 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 w s 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
| |
| mpar612 2006-08-13, 6:58 pm |
|
J.O. Aho wrote:
> mpar612 wrote:
>
> 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=&album_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.
| |
| Markus Ernst 2006-08-13, 6:58 pm |
| 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 w s 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
| |
| Webwasp 2006-08-13, 6:58 pm |
| go XXXX a piece of code you wrangled out of some!!
"mpar612" <mpar612@gmail.com> wrote in message
news:1155420727.058240.171280@p79g2000cwp.googlegroups.com...
> Webwasp wrote:
>
> 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.
>
| |
| Jerry Stuckle 2006-08-13, 6:58 pm |
| mpar612 wrote:
> J.O. Aho wrote:
>
>
>
> 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=&album_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.
jstucklex@attglobal.net
==================
| |
| Jerry Stuckle 2006-08-13, 6:58 pm |
| mpar612 wrote:
> Webwasp wrote:
>
>
>
> 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.
jstucklex@attglobal.net
==================
| |
| Johnny 2006-08-22, 9:58 pm |
|
"J.O. Aho" <user@example.net> wrote in message
news:4k47paFak9gkU1@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...tml#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
|
|
|
|
|