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 5591
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: 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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |