Click to See Complete Forum and Search --> : Unnecessary Warning on First Load of Page


TriZz
05-01-2008, 06:26 PM
Hey all,

I'm sure this is just a rookie mistake, but I can't seem to find a way around it. Perhaps someone can take a look and help me with a resolve:


while ($row = mysql_fetch_array($result))
{
if ($row['movieID'] == $movieID)
{
$match = "y";
}
}

if ($match != "y")
{
echo $movieID . " is not a valid movie ID - No delete made ***<br /><br />";
include 'footer.html';
die ();
}

mysql_query("DELETE FROM dvd WHERE movieID = '$movieID'")
or exit("<p>Error - Unable to execute query</p>");
echo $movieID . " was successfully deleted ***";

mysql_close($DBconnect);


What's happening is that when you FIRST load the page, it gives a warning saying " is not a valid movie ID - No delete made ***" because when the page first loads $match does NOT = 'y'.

Is there a way around this? I've tried making $match = 0 and putting an if statement that if $match = 0 then die (); but that just gives the warning of " was successfully deleted".

I'm so lost and frustrated. Any suggestions are greatly appreciated.

Thanks all,
TriZz

kredd
05-01-2008, 06:47 PM
hey, i'm assuming there is a form on the page that is supposed to be submitted and then have the sql run. so....try this:

wrap your sql in this and add a hidden field in your form named "process" with a value of 1 with the form method set to POST. this will only allow the sql to fire if the hidden field has been posted(ie - form is purposefully submitted with an actual movieID to be processed).

someone may have a better or more efficient idea but this always works for me.



if($_POST['process'] == 1) {

<<<SQL GOES INHERE >>>

}

TriZz
05-01-2008, 07:42 PM
@KREDD

Thanks a lot! Your solution worked brilliantly!

Hopefully one day, I'll be able to help those who were once me.

Again, thanks...I was getting so mad!

kredd
05-01-2008, 10:33 PM
no sweat! and i know exactly what you mean ;)