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("SE LECT * FROM survey WHERE FirstName =
'".$FirstName." ' AND LastName = '".$LastName ."' ");
$num_rows = mysql_num_rows( $result);
if($num_rows > 0){header("loca tion: ./oops.htm");};
//Check for repeat email
$result = mysql_query("SE LECT * FROM survey WHERE EmailAddress =
'".$EmailAddres s."' ");
$num_rows = mysql_num_rows( $result);
if($num_rows > 0){header("loca tion: ./oops.htm");};
//Check for existance of first name, last name, and email
if(!$FirstName) {header("locati on: ./oops.htm");};
if(!$LastName){ header("locatio n: ./oops.htm");};
if(!$EmailAddre ss){header("loc ation: ./oops.htm");};
$newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')");
$result=mysql_q uery($newrecord );
//Redirect to thankyou
header("locatio n: ./thanks.htm"); 2 5612
On Fri, 08 Aug 2003 23:22:19 GMT, "Paris_Suck s" <pa*********@ho tmail.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("SE LECT * 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($qu ery)
or die ("Query failed:<br>$que ry<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("loca tion: ./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("SE LECT * FROM survey WHERE EmailAddress = '".$EmailAddre ss."' "); $num_rows = mysql_num_rows( $result); if($num_rows > 0){header("loca tion: ./oops.htm");};
//Check for existance of first name, last name, and email if(!$FirstName) {header("locati on: ./oops.htm");}; if(!$LastName){ header("locatio n: ./oops.htm");}; if(!$EmailAddre ss){header("loc ation: ./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_q uery($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("locatio n: ./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.c om... On Fri, 08 Aug 2003 23:22:19 GMT, "Paris_Suck s" <pa*********@ho tmail.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("SE LECT * 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($qu ery) or die ("Query failed:<br>$que ry<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("loca tion: ./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("SE LECT * FROM survey WHERE EmailAddress = '".$EmailAddre ss."' "); $num_rows = mysql_num_rows( $result); if($num_rows > 0){header("loca tion: ./oops.htm");};
//Check for existance of first name, last name, and email if(!$FirstName) {header("locati on: ./oops.htm");}; if(!$LastName){ header("locatio n: ./oops.htm");}; if(!$EmailAddre ss){header("loc ation: ./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_q uery($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("locatio n: ./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 the string
"Select name From users Where password = PASSWORD('$testPass')"
and ran mysql_query() using the string. But nothing was returned. So I
decided to run a test and try to change a password from my php page using
the string
|
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 the manual):
A full table scan will be done for each combination of rows from the
|
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 table in MySQL with the path & filename to
the image.
I have successfully uploaded and performed an update query on the database,
but the problem I have is I cannot retain the primary key field in a
variable which is then used in a SQL update...
|
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 from allowing ODBC access) so I cannot
modify any tables or enable replication etc...
My initial thoughts on how to do this are:
1. Execute a query similar to the following to retrieve a list of rows and a
|
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 GPL'd
and force them to pay for a commercial license.
According to the lawyers I've consulted, based on the letter of the
GPL, here is the conclusion:
Commercial users of MySQL opting for the GPL'd version are not
compelled to release their...
|
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 a MySql shop or a Postgresql shop.
It's my opinion that we should be using PG, because of the full ACID
support, and the license involved. A consultant my company hired before
bringing me in is pushing hard for MySql, citing speed and community...
|
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 where someone
suggested to me I was spending too much time writing error messages,
and that I was therefore missing the benefit of using a scripting
language. The idea, apparently, is that the PHP interpreter writes all
the error messages that are...
|
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 problem.
http://www.jilp.org/vol9/v9paper10.pdf
Specifically, they measured the overhead of a bounds
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |