Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Just wanted to let you know that I registered today, and your site is fantastic. I found solutions to problems that I have been encountering for months!..."

Geography

Where in the world do Tek-Tips members come from?
max2474 (Programmer)
10 May 12 7:56
Hi. I am developing a site with two databases - one is for customers to apply to join as members, the other is a members database. Everything seemed to be working well, until I tried "bug hunting".

When a new member signs up, they are deleted from the first db and added to the second. If that member then uses the back button, hits F5, or calls the php page directly, problems start occurring.

I am convinced that the problem lies here :

CODE

...
            $_SESSION[exists] = "0";
            mysql_select_db("applydb", $con);
            $result = mysql_query("SELECT email FROM apply
                WHERE email = '$_SESSION[email]' LIMIT 1");
            while($row = mysql_fetch_array($result))
            {
                $_SESSION[exists] = "1";
            }
            mysql_close($con);
...
this code checks weather the person has applied or not. If they are found (exists=1) they are added to the new db and deleted from this one.

This is working perfectly in regular use. however, even after they have been deleted, recalling the page makes $_SESSION[exists] = "1" even when they dont, resulting in duplicate entries to the members database.

I have checked the applydb and it is empty.

adding this:

CODE

echo "registered exists is ".$_SESSION[exists];
to both the top and the bottom of the script, returns 0 then 1, saying it found the non-existent member :/

Again, just to iterate, this works perfectly with normal use. It is only when recalled that the error occurs.

This is what I used to delete the member:

CODE

<?php
                require("connectdb.php");
                mysql_select_db("applydb", $con);
                mysql_query("DELETE FROM apply WHERE email = '$_SESSION[email]' LIMIT 1");
                if (!$con)
                {  die('Error: ' . mysql_error());}
                mysql_close($con);
?>

I can include more script if wanted, but cannot see that it is relevant; the database is empty.

Is this perhaps just a peculiarity?

Hope this makes sense, and that you can help.
r937 (TechnicalUser)
10 May 12 9:08
this is a php issue, not a mysql issue

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

vacunita (Programmer)
10 May 12 10:13

Yup.

Forum: PHP is best suited for this question.

As a starter, I would question the need for 2 databases over an applicants table and a members table in the same DB?

Secondly, I suspect you are not checking your members db for the existence of the user you are trying to add to the applicant DB and subsequently to the members DB.

Thirdly and most importantly: It seems either you are not deleting the members off of the apply DB correctly or they are getting added back in. This:

CODE

while($row = mysql_fetch_array($result))
{
$_SESSION[exists] = "1";
}

Should not run if there are no rows returned, which means you are getting a row back based on your query.

With that said, there is no point in looping through at most a single row and then simply discarding the contents of the row. Instead using mysql_num_rows() to determine the amount of rows returned should be enough if you don't need to do anything with the row contents.

And finally, you should always condition your insertions so that you get no duplicates in either DB. Check for the existence of the user in both before inserting. And don't set the SESSION variable to 0 without checking before if its already set to something else. That would also prevent any unwanted insertions.

For more details on the PHP side, you can post this in Forum: PHP making sure you link to this thread so people there know what has been suggested already.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

max2474 (Programmer)
11 May 12 12:05
thanks for the tips. I am going to move over to the php forum as strange things are afoot :)

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close