473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Testing mysql query

Basically I am using PHP 5.1.2 with Apache 2.0.5 on a FreeBSD 5.4 box
with Mysql 4.1.1 running.

I am attempting to write information to a Mysql table called Jabber. I
can connect successfully, query data, and write data pretty much
without problem. My problem is this.

I am trying to do some duplicate checking on this table so I query the
dbase with the following:

/* Searching for username in Authreg database and assiging it to
variable */
$query1 = "SELECT * FROM `$table` WHERE username='$username'";
$query1_results = mysql_query($query1) or die("Query Failed");
$existing = mysql_result($query1_results, 0,0);

Problem is this.

When a user already exsits in database I have a conditional if
statement that looks like such:

/* Conditional statement that searches for exsiting username */
if ($username == $existing) {
die ("Please select a unique username");
} else {
....
}

And it errorr out telling me to, "Please select a unique username" as
stated above.

When I am adding a new user to the database above I get the following
error in my logs or in the browser depending on what --display-errors=
is set to in my php.ini.:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row
0 on MySQL result index 4 in /usr/local/www/sfg/add_jabber/add_test.php
on line 38

I know this error is happening as a result of the following line when
the user is not present in the database:

$existing = mysql_result($query1_results, 0,0);

So how would I write something that is conditional to test if the name
exsits in the database before allowing me to write to the various
tables. Any help appreciated.

Feb 10 '06 #1
2 2049
ch****@gmail.com wrote:
Basically I am using PHP 5.1.2 with Apache 2.0.5 on a FreeBSD 5.4 box
with Mysql 4.1.1 running.

I am attempting to write information to a Mysql table called Jabber. I
can connect successfully, query data, and write data pretty much
without problem. My problem is this.

I am trying to do some duplicate checking on this table so I query the
dbase with the following:

/* Searching for username in Authreg database and assiging it to
variable */
$query1 = "SELECT * FROM `$table` WHERE username='$username'";
$query1_results = mysql_query($query1) or die("Query Failed");
$existing = mysql_result($query1_results, 0,0);

Problem is this.

When a user already exsits in database I have a conditional if
statement that looks like such:

/* Conditional statement that searches for exsiting username */
if ($username == $existing) {
die ("Please select a unique username");
} else {
...
}

And it errorr out telling me to, "Please select a unique username" as
stated above.

When I am adding a new user to the database above I get the following
error in my logs or in the browser depending on what --display-errors=
is set to in my php.ini.:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row
0 on MySQL result index 4 in /usr/local/www/sfg/add_jabber/add_test.php
on line 38

I know this error is happening as a result of the following line when
the user is not present in the database:

$existing = mysql_result($query1_results, 0,0);

So how would I write something that is conditional to test if the name
exsits in the database before allowing me to write to the various
tables. Any help appreciated.


Check to see how many rows are returned. If the username doesn't exist
in the database, MySQL won't return anything.

Also - always check to see if result is not false!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 11 '06 #2
> So how would I write something that is conditional to test if the name
exsits in the database before allowing me to write to the various
tables. Any help appreciated.


$query1 = "SELECT * FROM `$table` WHERE username='$username'";
$query1_results = mysql_query($query1) or die("Query Failed");
if (mysql_num_rows($query1_results) > 0) {
echo "User already exists.";
}

Feb 11 '06 #3

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

Similar topics

0
by: JoeAley2003 | last post by:
Hi all. I recently installed all MySQL 4.1.1 including max RPMS. During the installation i used "--nodeps" on MAX package and at Shared-compat cause they were requiring the libssl.0.9.6 and...
0
by: Michael Weiner | last post by:
I know this is quite a bit off topic, but i was wondering if anyone else out there had any experience with Segue's Silk Performer load testing tools. More specifically, i am trying to compile a...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
11
by: Durai | last post by:
Hi All, I tested "concurrent testing" in MySQL. It works fine. But I couldn't do in PostgreSQL 7.3.4 on HPUX IPF. I got deadlock problem. I used the PHP script to update table( one script...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
3
by: Me Alone | last post by:
Hello: I am trying to edit some C code I found in "The definitive guide to using, programming, and administering MySQL" by Paul DuBois. This C client program connects and then segfaults when...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.