Thanks much for you reply. IT was the exit(); commands that I needed to
include.
Thanks again,
Jeff.
"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:sol8jv0n0dmfbnhn79vfilp99vgibtcqrn@4ax.com...[color=blue]
> On Fri, 08 Aug 2003 23:22:19 GMT, "Paris_Sucks" <paris_sucks@hotmail.com>
> wrote:
>[color=green]
> > I'm trying to redirect when testing for certain condidtions as shown
> >below. When the conditions are ture, it redirects, but still goes ahead[/color][/color]
and[color=blue][color=green]
> >processes the sql query. What am I doing wrong??? And then sometimes[/color][/color]
when[color=blue][color=green]
> >the conditions are correct, it doens't redirect. It appears to be very
> >inconsistent.
> >
> >Any suggestions would be greatly appreciated.[/color]
>
> Deep breath...
>[color=green]
> > //Check for repeat name
> > $result = mysql_query("SELECT * FROM survey WHERE FirstName =
> >'".$FirstName."' AND LastName = '".$LastName."' ");[/color]
>
> Problem 1: Any of the these queries could fail, but you're not checking[/color]
for[color=blue]
> errors.
>
> Never ignore the return value of mysql_query; if there's an error, it[/color]
returns[color=blue]
> false, and the reason for the error is available in mysql_error().
>
> For debugging use something like:
>
> $result = mysql_query($query)
> or die ("Query failed:<br>$query<br>Error: " . mysql_error());
>
> This will show you the error, which query caused it, and prevent your[/color]
script[color=blue]
> carrying on past a failed query and getting into even worse trouble with
> undefined variables and resource handles (as above).
>
> Problem 2 (possibly): Are those variables $FirstName and $LastName[/color]
properly[color=blue]
> escaped? i.e. are all single quotes turned into \' ?
>[color=green]
> > $num_rows = mysql_num_rows($result);[/color]
>
> Problem 3: All you're looking for is whether there is a row. However[/color]
you're[color=blue]
> fetching all the data from the database, then ignoring it.
>
> If you want to count how many rows match, use COUNT(*) in the SQL, and[/color]
fetch[color=blue]
> the single row it will return, and get the number from there.
>[color=green]
> > if($num_rows > 0){header("location: ./oops.htm");};[/color]
>
> Problem 4: You send an invalid Location header here. Location headers[/color]
have to[color=blue]
> be absolute URLs according to the HTTP specification.
>
> Problem 5: Just because you send a Location header does not mean the[/color]
script[color=blue]
> stops here. You'll carry on to the next bit, and possibly send more[/color]
Location[color=blue]
> headers. If you want to send the header then stop, use exit().
>[color=green]
> > //Check for repeat email
> > $result = mysql_query("SELECT * FROM survey WHERE EmailAddress =
> >'".$EmailAddress."' ");
> > $num_rows = mysql_num_rows($result);
> > if($num_rows > 0){header("location: ./oops.htm");};
> >
> > //Check for existance of first name, last name, and email
> > if(!$FirstName){header("location: ./oops.htm");};
> > if(!$LastName){header("location: ./oops.htm");};
> > if(!$EmailAddress){header("location: ./oops.htm");};
> >
> > $newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')");[/color]
>
> Problem 6: Why the brackets around the string?
> Problem 7: ($'Joe') ? Did you just mean ('Joe')? Or ('$Joe')?
>[color=green]
> > $result=mysql_query($newrecord);[/color]
>
> This will fail due Problem 7, and you'll carry on regardless due to[/color]
Problem 1[color=blue]
> despite it not having worked.
>[color=green]
> > //Redirect to thankyou
> > header("location: ./thanks.htm");[/color]
>
> --
> Andy Hassall (andy@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
> Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)[/color]