I'm trying to redirect when testing for certain condidtions as shown
below. When the conditions are ture, it redirects, but still goes ahead and
processes the sql query. What am I doing wrong??? And then sometimes when
the conditions are correct, it doens't redirect. It appears to be very
inconsistent.
Any suggestions would be greatly appreciated.
//Check for repeat name
$result = mysql_query("SELECT * FROM survey WHERE FirstName =
'".$FirstName."' AND LastName = '".$LastName."' ");
$num_rows = mysql_num_rows($result);
if($num_rows > 0){header("location: ./oops.htm");};
//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')");
$result=mysql_query($newrecord);
//Redirect to thankyou
header("location: ./thanks.htm"); 2 5585
On Fri, 08 Aug 2003 23:22:19 GMT, "Paris_Sucks" <pa*********@hotmail.com>
wrote: I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? And then sometimes when the conditions are correct, it doens't redirect. It appears to be very inconsistent.
Any suggestions would be greatly appreciated.
Deep breath...
//Check for repeat name $result = mysql_query("SELECT * FROM survey WHERE FirstName = '".$FirstName."' AND LastName = '".$LastName."' ");
Problem 1: Any of the these queries could fail, but you're not checking for
errors.
Never ignore the return value of mysql_query; if there's an error, it returns
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 script
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 properly
escaped? i.e. are all single quotes turned into \' ?
$num_rows = mysql_num_rows($result);
Problem 3: All you're looking for is whether there is a row. However you're
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 fetch
the single row it will return, and get the number from there.
if($num_rows > 0){header("location: ./oops.htm");};
Problem 4: You send an invalid Location header here. Location headers have to
be absolute URLs according to the HTTP specification.
Problem 5: Just because you send a Location header does not mean the script
stops here. You'll carry on to the next bit, and possibly send more Location
headers. If you want to send the header then stop, use exit().
//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')");
Problem 6: Why the brackets around the string?
Problem 7: ($'Joe') ? Did you just mean ('Joe')? Or ('$Joe')?
$result=mysql_query($newrecord);
This will fail due Problem 7, and you'll carry on regardless due to Problem 1
despite it not having worked.
//Redirect to thankyou header("location: ./thanks.htm");
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) ( http://www.andyh.co.uk)
Space: disk usage analysis tool ( http://www.andyhsoftware.co.uk/space)
Thanks much for you reply. IT was the exit(); commands that I needed to
include.
Thanks again,
Jeff.
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:so********************************@4ax.com... On Fri, 08 Aug 2003 23:22:19 GMT, "Paris_Sucks" <pa*********@hotmail.com> wrote:
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead
andprocesses the sql query. What am I doing wrong??? And then sometimes
whenthe conditions are correct, it doens't redirect. It appears to be very inconsistent.
Any suggestions would be greatly appreciated. Deep breath...
//Check for repeat name $result = mysql_query("SELECT * FROM survey WHERE FirstName = '".$FirstName."' AND LastName = '".$LastName."' ");
Problem 1: Any of the these queries could fail, but you're not checking
for errors.
Never ignore the return value of mysql_query; if there's an error, it
returns 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
script 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
properly escaped? i.e. are all single quotes turned into \' ?
$num_rows = mysql_num_rows($result); Problem 3: All you're looking for is whether there is a row. However
you're 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
fetch the single row it will return, and get the number from there.
if($num_rows > 0){header("location: ./oops.htm");}; Problem 4: You send an invalid Location header here. Location headers
have to be absolute URLs according to the HTTP specification.
Problem 5: Just because you send a Location header does not mean the
script stops here. You'll carry on to the next bit, and possibly send more
Location headers. If you want to send the header then stop, use exit().
//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')"); Problem 6: Why the brackets around the string? Problem 7: ($'Joe') ? Did you just mean ('Joe')? Or ('$Joe')?
$result=mysql_query($newrecord);
This will fail due Problem 7, and you'll carry on regardless due to
Problem 1 despite it not having worked.
//Redirect to thankyou header("location: ./thanks.htm");
-- Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk) Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Victor |
last post by:
In my mysql database, I've stored all the passwords using the PASSWORD()
function. Now I'm running a test and need to compare the password in my php
document to that saved in the database. I used...
|
by: Doug |
last post by:
I have a pretty long query that ends with
ORDER BY R.r_recent_hits DESC LIMIT 0, 1
I also have an index on R.r_recent_hits. I did an explain select and
got this:
ALL - which means (from...
|
by: dave |
last post by:
Hello there,
I am at my wit's end ! I have used the following script succesfully to
upload an image to my web space. But what I really want to be able to do is
to update an existing record in a...
|
by: Kevin Gale |
last post by:
Hi.
I need to replicate data (approx. 10,000 records) from a mySQL database into
a different (non mySQl) database automatically on a regular basis. I have no
control over the mySQL server (apart...
|
by: Philip Stoev |
last post by:
Hi all,
Please tell me if any of this makes sense. Any pointers to relevant
projects/articles will be much appreciated.
Philip Stoev
http://www.stoev.org/pivot/manifest.htm
...
|
by: B. Pigman |
last post by:
There have been many questions as to the viability of MySQL's
assertion that it can dictate what constitutes a derived work in order
to use the GPL against developers who don't wish their software...
|
by: John Wells |
last post by:
Yes, I know you've seen the above subject before, so please be gentle with
the flamethrowers.
I'm preparing to enter a discussion with management at my company
regarding going forward as either...
|
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project...
|
by: jacob navia |
last post by:
We hear very often in this discussion group that
bounds checking, or safety tests are too expensive
to be used in C.
Several researchers of UCSD have published an interesting
paper about this...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |