delete message function

delete message function

am 14.06.2011 07:31:08 von Chris Stinemetz

I created the below delete function, but it doesn't seem to be working
correctly. When I enter the correct password it get my echo "Incorrect
Password Did not Delete!" When I leave the password blank the message
will delete from mysql table.

Am I missing something??

Thanks in advance,

Chris

function delete_message(&$msg) {
extract($msg, EXTR_PREFIX_ALL, 'row');
$result = mysql_query("SELECT ID FROM mbmsgs WHERE Parent = $row_ID;");

while ($row = mysql_fetch_array($result)) {
delete_message($row);
}
mysql_query("DELETE FROM mbmsgs WHERE ID = $row_ID;");
}

$result = mysql_query("SELECT Title, Password FROM mbmsgs WHERE ID
= {$_REQUEST['Msg']};");
if (!$result) exit;
if (!mysql_num_rows($result)) exit;
extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'msg');

if (isset($_POST['Password'])) {
if (sha1($_POST['Password']) != $msg_Password) {
echo "Incorrect password did not delete!";
exit;

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: delete message function

am 14.06.2011 07:50:39 von Chris Stinemetz

On Tue, Jun 14, 2011 at 12:31 AM, Chris Stinemetz
wrote:
> I created the below delete function, but it doesn't seem to be working
> correctly. When I enter the correct password it get my echo "Incorrect
> Password Did not Delete!" When I leave the password blank the message
> will delete from mysql table.
>
> Am I missing something??
>
> Thanks in advance,
>
> Chris

Sorry. I left out the call to the function. Below is the whole snippit
for the function and call.

function delete_message(&$msg) {
extract($msg, EXTR_PREFIX_ALL, 'row');
$result = mysql_query("SELECT ID FROM mbmsgs WHERE Parent = $row_ID;");

while ($row = mysql_fetch_array($result)) {
delete_message($row);
}
mysql_query("DELETE FROM mbmsgs WHERE ID = $row_ID;");
}

$result = mysql_query("SELECT Title, Password FROM mbmsgs WHERE ID
= {$_REQUEST['Msg']};");
if (!$result) exit;
if (!mysql_num_rows($result)) exit;
extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'msg');

if (isset($_POST['Password'])) {
if (sha1($_POST['Password']) != $msg_Password) {
echo "Incorrect password did not delete!";
exit;
}
$result = mysql_query("SELECT ID FROM mbmsgs WHERE Parent =
{$_POST['Msg']};");

while ($row = mysql_fetch_array($result)) {
delete_message($row);
}

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: delete message function

am 14.06.2011 14:07:38 von Simcha Younger

On Tue, 14 Jun 2011 00:50:39 -0500
Chris Stinemetz wrote:

> On Tue, Jun 14, 2011 at 12:31 AM, Chris Stinemetz
> wrote:
> > I created the below delete function, but it doesn't seem to be working
> > correctly. When I enter the correct password it get my echo "Incorrect
> > Password Did not Delete!" When I leave the password blank the message
> > will delete from mysql table.
> >
> > Am I missing something??

>
> $result = mysql_query("SELECT Title, Password FROM mbmsgs WHERE ID
> = {$_REQUEST['Msg']};");
> extract(mysql_fetch_array($result), EXTR_PREFIX_ALL, 'msg');
>
> if (isset($_POST['Password'])) {
> if (sha1($_POST['Password']) != $msg_Password) {
> echo "Incorrect password did not delete!";
> exit;
> }

It sounds like the password is not set in the database. What do you get if you dump the result of your first query?
Also, you should avoid extract, it litters your code with dead and untraceable variables. Use $array['msg_Passowrd'] instead.

--
Simcha Younger

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php