why doesn't this delete the record I want it to delete?

This is a discussion on why doesn't this delete the record I want it to delete? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; <?php //db & table names used to connect include ("connect.php"); //display a list of names preceeded ...


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-11-2007
Mr. Newt
 
Posts: n/a
Default why doesn't this delete the record I want it to delete?

<?php
//db & table names used to connect
include ("connect.php");
//display a list of names preceeded by id #
include ("display_names.php");
?>
<p>Which record would you like to delete?</p>
<P>Enter Record #<br>
<input type=text name="id" size=20>
<input type=submit name="submit" value="Delete Record">
<?php
mysql_query("DELETE FROM testtable WHERE id=$id");
?>

The above deletes the last record in the table. Obviously it's not getting
the # that is being entered. Any help?

Thanks.

Robert


Reply With Quote
  #2 (permalink)  
Old 03-11-2007
Steve Belanger
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?

first i would put your HTML piece inside a FORM tag and speficy it to go as
POST, and from there use the fields to perform the delete. like in the
following example

<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<p>Which record would you like to delete?</p>
<P>Enter Record #<br>
<input type=text name="id" size=20>
<input type=submit name="submit" value="Delete Record">
</form>

This form would basically reload the same page but pass the FORM information
to it, and form there in your SQL query you would use something like that:

if (!empty($_POST))
{
mysql_query("DELETE FROM testtable WHERE id='{$_POST['id']}'");
}

i enclosed it within an IF statement so that it does not get called if the
$_POST array is empty. Eventually you would want to add more validation such
as checking the referrer page to ensure that the delete request came from
this page only (and not from another domain who might want to try to hijack
your form)

Hope this helps.

Steve.

"Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com. ..
> <?php
> //db & table names used to connect
> include ("connect.php");
> //display a list of names preceeded by id #
> include ("display_names.php");
> ?>
> <p>Which record would you like to delete?</p>
> <P>Enter Record #<br>
> <input type=text name="id" size=20>
> <input type=submit name="submit" value="Delete Record">
> <?php
> mysql_query("DELETE FROM testtable WHERE id=$id");
> ?>
>
> The above deletes the last record in the table. Obviously it's not
> getting
> the # that is being entered. Any help?
>
> Thanks.
>
> Robert
>
>



Reply With Quote
  #3 (permalink)  
Old 03-11-2007
Mr. Newt
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?

Thanks Steve. Works great.

"Steve Belanger" <desktop@ebinformatique.com> wrote in message
news:XKYIh.76303$cE3.52823@edtnps89...
> first i would put your HTML piece inside a FORM tag and speficy it to go
> as POST, and from there use the fields to perform the delete. like in the
> following example
>
> <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
> <p>Which record would you like to delete?</p>
> <P>Enter Record #<br>
> <input type=text name="id" size=20>
> <input type=submit name="submit" value="Delete Record">
> </form>
>
> This form would basically reload the same page but pass the FORM
> information to it, and form there in your SQL query you would use
> something like that:
>
> if (!empty($_POST))
> {
> mysql_query("DELETE FROM testtable WHERE id='{$_POST['id']}'");
> }
>
> i enclosed it within an IF statement so that it does not get called if the
> $_POST array is empty. Eventually you would want to add more validation
> such as checking the referrer page to ensure that the delete request came
> from this page only (and not from another domain who might want to try to
> hijack your form)
>
> Hope this helps.
>
> Steve.
>
> "Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
> news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com. ..
>> <?php
>> //db & table names used to connect
>> include ("connect.php");
>> //display a list of names preceeded by id #
>> include ("display_names.php");
>> ?>
>> <p>Which record would you like to delete?</p>
>> <P>Enter Record #<br>
>> <input type=text name="id" size=20>
>> <input type=submit name="submit" value="Delete Record">
>> <?php
>> mysql_query("DELETE FROM testtable WHERE id=$id");
>> ?>
>>
>> The above deletes the last record in the table. Obviously it's not
>> getting
>> the # that is being entered. Any help?
>>
>> Thanks.
>>
>> Robert
>>
>>

>
>



Reply With Quote
  #4 (permalink)  
Old 03-11-2007
Steve Belanger
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?

no problem. ask anytime.


"Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
news:vs2dnTxRTpow9WnYnZ2dnUVZ_o6gnZ2d@comcast.com. ..
> Thanks Steve. Works great.
>
> "Steve Belanger" <desktop@ebinformatique.com> wrote in message
> news:XKYIh.76303$cE3.52823@edtnps89...
>> first i would put your HTML piece inside a FORM tag and speficy it to go
>> as POST, and from there use the fields to perform the delete. like in the
>> following example
>>
>> <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
>> <p>Which record would you like to delete?</p>
>> <P>Enter Record #<br>
>> <input type=text name="id" size=20>
>> <input type=submit name="submit" value="Delete Record">
>> </form>
>>
>> This form would basically reload the same page but pass the FORM
>> information to it, and form there in your SQL query you would use
>> something like that:
>>
>> if (!empty($_POST))
>> {
>> mysql_query("DELETE FROM testtable WHERE id='{$_POST['id']}'");
>> }
>>
>> i enclosed it within an IF statement so that it does not get called if
>> the $_POST array is empty. Eventually you would want to add more
>> validation such as checking the referrer page to ensure that the delete
>> request came from this page only (and not from another domain who might
>> want to try to hijack your form)
>>
>> Hope this helps.
>>
>> Steve.
>>
>> "Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
>> news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com. ..
>>> <?php
>>> //db & table names used to connect
>>> include ("connect.php");
>>> //display a list of names preceeded by id #
>>> include ("display_names.php");
>>> ?>
>>> <p>Which record would you like to delete?</p>
>>> <P>Enter Record #<br>
>>> <input type=text name="id" size=20>
>>> <input type=submit name="submit" value="Delete Record">
>>> <?php
>>> mysql_query("DELETE FROM testtable WHERE id=$id");
>>> ?>
>>>
>>> The above deletes the last record in the table. Obviously it's not
>>> getting
>>> the # that is being entered. Any help?
>>>
>>> Thanks.
>>>
>>> Robert
>>>
>>>

>>
>>

>
>



Reply With Quote
  #5 (permalink)  
Old 03-12-2007
Sean
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?

"Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com. ..
> <?php
> //db & table names used to connect
> include ("connect.php");
> //display a list of names preceeded by id #
> include ("display_names.php");
> ?>
> <p>Which record would you like to delete?</p>
> <P>Enter Record #<br>
> <input type=text name="id" size=20>
> <input type=submit name="submit" value="Delete Record">
> <?php
> mysql_query("DELETE FROM testtable WHERE id=$id");
> ?>
>
> The above deletes the last record in the table. Obviously it's not
> getting
> the # that is being entered. Any help?
>
> Thanks.
>
> Robert
>
>


Looks correct.

Comment out the deletion line and add in

echo "Record to be deleted is $id";

To check the id of the record to go.

You could also query the table to check that there is only only record with
the matching 'id'.





Sean



Reply With Quote
  #6 (permalink)  
Old 03-13-2007
Steve Belanger
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?

if he does not specify a form to submit to then it will likely not work as
intended. Not to mention that depending of server configuration (for
instance register_globals being at Off) then it will not work as php will
not know where $id is coming from.


"Sean" <sean.anderson@[nospam]oakleafgroup.biz> wrote in message
news:1173698341.123284@kestrel.skynet.co.uk...
> "Mr. Newt" <lektrikpuke@_yahoo.com> wrote in message
> news:EICdnVlmxetj3GnYnZ2dnUVZ_qunnZ2d@comcast.com. ..
>> <?php
>> //db & table names used to connect
>> include ("connect.php");
>> //display a list of names preceeded by id #
>> include ("display_names.php");
>> ?>
>> <p>Which record would you like to delete?</p>
>> <P>Enter Record #<br>
>> <input type=text name="id" size=20>
>> <input type=submit name="submit" value="Delete Record">
>> <?php
>> mysql_query("DELETE FROM testtable WHERE id=$id");
>> ?>
>>
>> The above deletes the last record in the table. Obviously it's not
>> getting
>> the # that is being entered. Any help?
>>
>> Thanks.
>>
>> Robert
>>
>>

>
> Looks correct.
>
> Comment out the deletion line and add in
>
> echo "Record to be deleted is $id";
>
> To check the id of the record to go.
>
> You could also query the table to check that there is only only record
> with the matching 'id'.
>
>
>
>
>
> Sean
>
>



Reply With Quote
  #7 (permalink)  
Old 03-13-2007
Sean
 
Posts: n/a
Default Re: why doesn't this delete the record I want it to delete?


"Steve Belanger" <desktop@ebinformatique.com> wrote in message
news:jPnJh.90170$cE3.1083@edtnps89...
> if he does not specify a form to submit to then it will likely not work as
> intended. Not to mention that depending of server configuration (for
> instance register_globals being at Off) then it will not work as php will
> not know where $id is coming from.
>
>


Good point(s).



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 07:06 AM.


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