Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All seems to work Ok, but get an error report!

Status
Not open for further replies.

wudz

Programmer
Mar 28, 2001
135
GB
wudz (Programmer) 10 Jan 06 14:47
Hi,
I am a newbie to php/sql and getting an error doing a data check, it carries out the check OK and returns the correct reply if the input email already exists in the db...if a new email is input and is not yet in the db it drops through OK and it does the upload in a later bit of code and displays the confirmation html.... ALL WELL!!!!, BUT always gives this error:-

Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 18 in /home/ on line 75

and this is the part of the script that does the check and also gives the error:-

// check email if already invited

$result = mysql_query("SELECT user_id from AUCTION_invitedbuyerslist WHERE list_name = '$friend_email'");
$intro_id = mysql_result($result,0);
if ($intro_id > "0" ){
$friend_email="";
$friend_name="";
$TPL_error_text = $ERR_115c; // E-mail friend already introduced
}
Forgive me if it is obvious, but I am a Flash graphics bloke now trying to learn SQL and PHP, but at 60+ finding it a bit slow.....a lot slow..hi

All help will be appreciated and explaination.

John
 
Are you sure that your query will return any rows? If not, you can't use mysql_result() to move to result row 0, as there is no such thing. That would explain the error.

You could do as rac2 has suggested in thread436-1174832 and use mysql_num_rows() to determine the number of rows in your result set before trying to manipulate the set.

Why are you retrieving this row? Perhaps you should be fetching a COUNT rather than rows.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi thanks for your repy, I could well be doing the check wrong, only my 2nd week trying to add to and modify an existing script so really it's all new to me.
the action I require is..
A signed in user can recommend a friend by filling in friend name and email address.
I have a TABLE AUCTION_invitedbuyerslist that stores all invited users consisting of 3 fields.. iist_name (email add)PRIMARY, user_id (recommender id), credit_passed (used to tag if the recommender as received his credits y/n)..
I wish to check if the recommended user email is already on the db if yes tell user, if not drop through and update the above TABLE...
Before I added the check all worked perfect but allowed duplicate inputs..
Hope all the above make sense.

Cheers

John;
PS the total script is not too long I could post it, may make more sense

 
Hi,
I want to check the submitted recommended friends email ($friend_email) against past stored recommended friends( list_name )to check if it is unique if it is,a later section of script submits it along with the recommender id..etc...

Hope it helps..

Cheers
John
 
So you want to know the number of times the email appears in the table? It sounds to me your query should be something like:

SELECT count(*) from AUCTION_invitedbuyerslist WHERE list_name = '$friend_email'"

The query will always return exactly one row with a single column. And that column will be the number of entries in the column list_name that match the value of $friend_email.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi,
Not so much as to see how many times it is there, as it is a new database and I wish to stop duplication occuring from the start. A situation may occur where two indvidual existing users may know the same person and one may have already recommended them and it would have then been posted to the db. If then the other person recommends the same person it tell them they are already recommended and on the db, so not update would be allowed..hence the search to see if it already exists.

Hope this helps
cheers
John
 
Oh, the user_id query...think I have gone wrong...I think I used it as an error check, if not empty and both emails match then it must be posted, but as I write this I think the it is totally wrong,,,Just want the check as mentioned in the last post...
If emails matched inform already on db, clear form for perhaps input of another friend.
If no match, drop through and allow post to db, load confirmation page.

Old age.......

Cheers

John
 
i think you misunderstood sleipnir214's post. you DO in fact want to do a count to detemine whether the answer is zero or more than zero.

try the following:
Code:
if (isset($_REQUEST['friend_email']) && $_REQUEST['friend_email'] != ""):
$friend_email = trim($_REQUEST['friend_email']);
//you may want to add some escaping here depending on your ini settings

$result = mysql_query("SELECT count(*) as cnt  from AUCTION_invitedbuyerslist WHERE list_name = '$friend_email'");
if (mysql_result($result,0) !=0)://ie there is another entry
                 $friend_email="";
                 $friend_name="";
                 $TPL_error_text = $ERR_115c; // E-mail friend already introduced
else:
//all is well - store in database
endif;
else:
//either form wasnt submitted or field was empty
endif;
 
Many thanks Sleipinr214 and jpadie, sorry for my short coming in terms and understanding(did BASIC years ago),I had got it in my head that a query always looked at the first field and if the match was fulfiled you stopped with a TRUE and could then extract data on that row if needed...

This count thing has got me....more reading..Hi.

I do appreciate all the help given and is and will help in my understanding of the coding..

Hi Jpadie, I will alter tonight when I have more time and give it a whirl.....Thanks

Cheers lads

John
 
Hi jpadie,

GREAT! all working as I wanted added another search of the main user db to check if the friend had registered on their own, using your guidance script..really pleased that help is available..
I am a member of the Flash forum and they also have a great bunch of guys.

Many thanks for all help

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top