473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A simple IF condition.

I have a simple IF condition to check whether an entered town name for
a search actually exists in the database.

The form search produces $townsearch

The check should return "Cannot Find The Town" if $townsearch does not
correspond to a recognised townname in the database.

The database is correct, and the SQL query OK.

So why can I type anything in and it accepts it??

(Day 4 of learning PHP)

Alec

<?php $townsearch = $_GET['town']; ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="town" size="20" value="<?php echo $townsearch;
?>" />&nbsp;
<input type="submit" value="GO" />

<?php
$check = @mysql_query ("SELECT townname FROM site01_towns WHERE
townname='$town search'");
if (!$check)
{
echo '<p>Cannot Find The Town</p>';
exit();

}

?>

Sep 2 '05 #1
4 1792
*** Alec wrote/escribió (2 Sep 2005 05:46:29 -0700):
$check = @mysql_query ("SELECT townname FROM site01_towns WHERE
townname='$town search'");
if (!$check)
{
echo '<p>Cannot Find The Town</p>';
exit();

}


Let's check mysql_query() manual page:

"Only for SELECT,SHOW,EXP LAIN or DESCRIBE statements mysql_query() returns
a resource identifier or FALSE if the query was not executed correctly.
[...] A non-FALSE return value means that the query was legal and could be
executed by the server. It does not indicate anything about the number of
rows affected or returned. It is perfectly possible for a query to succeed
but affect no rows or return no rows."

Your if condition will only be FALSE if you have a syntax error in your SQL
query.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Sep 2 '05 #2
Give

if (mysql_num_rows ($check) == 0)

a try instead.

Sep 2 '05 #3
Is this the entire code?
If so, you don't have a mysql connection yet (afaik).

And *please* escape your search object:
http://www.php.net/manual/en/functio...ape-string.php

Greetings Frizzle.

Sep 2 '05 #4
Dracolytch

If (mysql_num_rows ($check) ==0)

Works nicely thank you very much....

Am learning as I am doing, but eventually....

Sep 2 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2114
by: Ryno Rijnsburger | last post by:
I am busy packaging our product as a standard Setup project in VS.NET that uses a bunch of merge modules (basically, a merge module for every key infrastructure component in our system). Part of the installation needs to "dump" a bunch of files (third party product's project files) to the user's system. These files are transient in nature in that the user may choose
6
1493
by: SB | last post by:
This while loop keeps repeating even when a correct character is entered.... cout<<endl<<"What day would you like to schedule the appointment?"<<endl; cout<<endl<<"Enter 'M' for Monday, 'T' for Tuesday, 'W' for Wednesday, 'H' for Thursday \n"<< "and 'F' for Friday: "; cin>>day; while (day != "M" || day != "m" || day != "T" || day != "t" || day != "W" || day != "w" || day != "H" || day != "h" || day != "F" || day != "f")
4
1543
by: motessa | last post by:
Hello All, I have a quick, easy question. Hopefully, someone will give me a hint. I will greatly appreciate any help. I am pretty new to Access. I have created a Main Menu in Form in Access. When I click on Main Menu, an interface popups. In the interface, I have 2 buttons. For example:
32
5125
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 * 10^12) it's pretty efficient, it took 15 minutes to compute the first 1,000,000 primes.
51
8299
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
20
2503
by: Brian Tkatch | last post by:
An ORDER BY a simple-integer inside a FUNCTION, results in SQL0440N, unless the FUNCTION expects an INTEGER as its parameter. For example: DECLARE GLOBAL TEMPORARY TABLE A(A CHAR(1)) INSERT INTO SESSION.A VALUES ('a'), ('b') CREATE FUNCTION A(A char(1)) RETURNS char(1) DETERMINISTIC NO EXTERNAL ACTION RETURN A SELECT A FROM SESSION.A ORDER BY A(1) DROP FUNCTION A DROP TABLE SESSION.A
26
495
by: jacob navia | last post by:
Summary: I have changed (as proposed by Chuck) the code to use isalpha() instead of (c>='a' && c <= 'z') etc. I agree that EBCDIC exists :-) I eliminated the goto statement, obviously it is better in a tutorial to stick to structured programming whenever possible...
1
1068
by: bluesteel | last post by:
I wanted to know whether it was possible to write a while where the condition was checked in every instruction and stopped if false, i mean: Considering the following coda: condition instruction 1; instruction 2; instruction n; and it should check whether the condition is true or not in every step. Does something like that exist? I could do as follows:
1
1670
by: DennyLoi | last post by:
Hi there I am writing a simple while loop which terminates on the condition that a certain value is found, as follows std::string question = q.quest().que(); std::string answer = q.ans().answer(); std::string graphic = q.inf().info(); std::string english1; std::string english2;
17
5825
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /* Simple Thread Object ______________________________________________________________*/ #include <pthread.h> extern "C" void* thread_entry(void*);
0
9546
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,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
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...
1
7570
isladogs
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...
0
5467
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...
1
4146
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
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.