By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,747 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,747 IT Pros & Developers. It's quick & easy.

Database

P: n/a
Ken
I have been working on this problem for a few days.

When I write data into a sql database, the results are duplicate listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die ('Cannot
connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

As you can see, I have been working on this for some time, id=131.

Any suggestions for stopping the insertion of the duplicate rows?

Thanks.

Ken
Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
"Ken" <kk******@wi.rr.com> wrote in
news:Nl******************@twister.rdc-kc.rr.com:
I have been working on this problem for a few days.

When I write data into a sql database, the results are duplicate
listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die
('Cannot connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

As you can see, I have been working on this for some time, id=131.


The most obvious possibility is that the script is somehow getting executed
multiple times. Change that mysql_query into a simple echo and see how
many of them you get.

BTW, there's obviously more to your code than you've shown us (you call
session_start() but don't show any use of session variables, you don't
close your database connection, etc.). It's possible the problem lies
elsewhere. If you haven't already done so, strip out *everything* but the
insertion code and see if you can duplicate the problem. Very often you'll
get an "aha!" when you do that; if not, post the complete but stripped-down
code, *copying and pasting it* into your post rather than retyping it (code
invariably mutates when you retype it, and sometimes the mutation actually
fixes the problem because you typed what you meant to write rather than
what you really did write).
Jul 17 '05 #2

P: n/a
I noticed that Message-ID: <Nl******************@twister.rdc-kc.rr.com>
from Ken contained the following:

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";


Where are the values coming from?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3

P: n/a
Ken
There is more code but it has all been commented out.
I left the session_start() in case it was an underlying cause. But I also
commented out session_start, and had the same problem.

I agree the page seems to be running twice but I cannot figure out why.

Good thought about using echo.

I just did that and the statement only displays once per run. "But a good
idea for future problems." Notice that I have an
echo "Data Transfer Complete"; statement. That only displays once and the
page does not seem to rewrite(refresh) between rows in the database.

I actual copied the code but changed the username, password and database &
table names as you would expect.

I will copy the active code into a test.php file and see what happens.

Thanks for the suggestions.

Ken
When I write data into a sql database, the results are duplicate
listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die
('Cannot connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

As you can see, I have been working on this for some time, id=131.
The most obvious possibility is that the script is somehow getting

executed multiple times. Change that mysql_query into a simple echo and see how
many of them you get.

BTW, there's obviously more to your code than you've shown us (you call
session_start() but don't show any use of session variables, you don't
close your database connection, etc.). It's possible the problem lies
elsewhere. If you haven't already done so, strip out *everything* but the
insertion code and see if you can duplicate the problem. Very often you'll get an "aha!" when you do that; if not, post the complete but stripped-down code, *copying and pasting it* into your post rather than retyping it (code invariably mutates when you retype it, and sometimes the mutation actually
fixes the problem because you typed what you meant to write rather than
what you really did write).

Jul 17 '05 #4

P: n/a
Ken
To troubleshoot the problem, I am only using one variable, website, and the
value for the variable is text, website_es, listed as ' website_es ' without
the spaces after ' and before '.

Ken

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:ep********************************@4ax.com...
I noticed that Message-ID: <Nl******************@twister.rdc-kc.rr.com>
from Ken contained the following:

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";


Where are the values coming from?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #5

P: n/a
Hi Ken,

On Sun, 4 Apr 2004 19:02:07 -0500, "Ken" <kk******@wi.rr.com> wrote:
I have been working on this problem for a few days.

When I write data into a sql database, the results are duplicate listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die ('Cannot
connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

In addition to the others comments, are you mayeb using a header
("Location: "...)?

Note that the code after the header will be excuted if you don't use
die();

HTH, Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #6

P: n/a
Ken
I copied the code just needed to transfer the data into another file. It
still produced the problem.

But 30 minutes later, the transfer was correct. I think the problem is in
the db manager I am using DB Manager Professional 2.2.0 from DB Tools. If I
run the code in a fast sequence numerous times, the data display locks up.
I need to close the program and then reopen it to show the new data.
BDManager is probably causing the duplicate entries.

I was going to use phpmyadmin but the readme said the script must be in the
root directory and I did not want it intermixed with my code.

What are you using to monitor the database?

Thanks for the help.

Ken

I am using
"Eric Bohlman" <eb******@earthlink.net> wrote in message
news:Xn*******************************@130.133.1.4 ...
"Ken" <kk******@wi.rr.com> wrote in
news:Nl******************@twister.rdc-kc.rr.com:
I have been working on this problem for a few days.

When I write data into a sql database, the results are duplicate
listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die
('Cannot connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

As you can see, I have been working on this for some time, id=131.
The most obvious possibility is that the script is somehow getting

executed multiple times. Change that mysql_query into a simple echo and see how
many of them you get.

BTW, there's obviously more to your code than you've shown us (you call
session_start() but don't show any use of session variables, you don't
close your database connection, etc.). It's possible the problem lies
elsewhere. If you haven't already done so, strip out *everything* but the
insertion code and see if you can duplicate the problem. Very often you'll get an "aha!" when you do that; if not, post the complete but stripped-down code, *copying and pasting it* into your post rather than retyping it (code invariably mutates when you retype it, and sometimes the mutation actually
fixes the problem because you typed what you meant to write rather than
what you really did write).

Jul 17 '05 #7

P: n/a
In article <Nl******************@twister.rdc-kc.rr.com>,
"Ken" <kk******@wi.rr.com> wrote:
When I write data into a sql database, the results are duplicate listings:
[...]
After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

This may not address the underlying problem (insert happening multiple
times) but would it not also be a good idea to define the 'website'
column as UNIQUE if it isn't supposed to contain duplicate values?

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #8

P: n/a
Ido
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 05 Apr 2004 00:45:52 GMT
"Ken" <kk******@wi.rr.com> wrote:
To troubleshoot the problem, I am only using one variable, website,
and the value for the variable is text, website_es, listed as '
website_es ' without the spaces after ' and before '.
Ken, it looks like you're dictating code from another project. The
reference to 'website_es' is not a variable, but rather a literal. Try
this out for size:

// make sure $website_es exists beforehand!
if (isset($website_es)) {
$website_es = base64_encode($website_es) // to make it SQL-safe
mysql_query("INSERT INTO tablename (website) Values ('$website_es')");
echo "Data Transfer Complete";
}

You were missing the dollar sign next to website_es...this isn't ASP, in
PHP you refer to variables by prefixing their name with a $.

When reading the value, use base64_decode to return the SQL-safe form to
its original form. For example:

if ($result = @mysql_query("SELECT website FROM tablename"))
{
while($row = @mysql_fetch_assoc($result))
{
$website_es = base64_decode($row['website']);
$website_id = $row['id'];
echo "id = $id, website = $website_es <br>";
}
}

There are some features I've used above that you will probably not
immediately be familiar with, but they are all fully explained in the
php manual at www.php.net. RTFM, as it were. :)

Hope this helps,

Ido

Ken

"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:ep********************************@4ax.com...
I noticed that Message-ID:
<Nl******************@twister.rdc-kc.rr.com> from Ken contained the
following:

mysql_query("INSERT INTO tablename (website)
Values('website_es')"); echo "Data Transfer Complete";


Where are the values coming from?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAcP10mhQsAkXAJP0RAn9VAKC35RTxWrv4FSLKL5ieNo gdE0ZE5gCeIcPT
8H0IWyg4qevhiZJ5uGJkF2c=
=gEx5
-----END PGP SIGNATURE-----
Jul 17 '05 #9

P: n/a
Ken
More information on the problem:

I am now up to id =411

-------------------------------
I just had a break through on determining what code is causing the duplicate
data.

If you run the code listed below without the session_start(); a single set
of data is transferred.

If you add: session_start(); to the code under the <?php and run the
page once, a single set of data is transferred.

Click on edit in the editor and then run, two sets of data are transferred.
Repeat the edit and run, two sets of data is transferred. Interesting!!!!

Summary: the results is caused by the session_start(); code.
Interesting!!!!

Has anyone else experience this error?

Suggestions?
-------------------------------------
"Ken" <kk******@wi.rr.com> wrote in message
news:Nl******************@twister.rdc-kc.rr.com...
I have been working on this problem for a few days.

When I write data into a sql database, the results are duplicate listings:

PHP Code:
<?php
session_start();
$dbh=mysql_connect ("localhost", "username", "password") or die ('Cannot
connect to the database: ' . mysql_error());
mysql_select_db ("database name") or die ("Cannot locate database:
".mysql_error());

mysql_query("INSERT INTO tablename (website) Values('website_es')");
echo "Data Transfer Complete";
?>

After emptying the table and running the PHP script:
The results in the database:
id website
130 website_es
131 website_es

As you can see, I have been working on this for some time, id=131.

Any suggestions for stopping the insertion of the duplicate rows?

Thanks.

Ken

Jul 17 '05 #10

P: n/a
I noticed that Message-ID: <aU*******************@twister.rdc-kc.rr.com>
from Ken contained the following:
I just had a break through on determining what code is causing the duplicate
data.

If you run the code listed below without the session_start(); a single set
of data is transferred.

If you add: session_start(); to the code under the <?php and run the
page once, a single set of data is transferred.

Click on edit in the editor and then run, two sets of data are transferred.
Repeat the edit and run, two sets of data is transferred. Interesting!!!!

Summary: the results is caused by the session_start(); code.
Interesting!!!!


Eh?

It sounds like your editor is running the code. Try adding a button and
a form and making the insert conditional on pressing the button.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #11

P: n/a

"Ken" <kk******@wi.rr.com> wrote in message
news:RG*******************@twister.rdc-kc.rr.com...
<snip>
I was going to use phpmyadmin but the readme said the script must be in the root directory and I did not want it intermixed with my code.

<snip>

What? Where does it say that? That's not the case (why would it be?). You
might have read "root user" for the database and got it mixed up. I'm sure
it's installable anywhere you see fit.

I can't praise phpMyAdmin enough for day-to-day MySQL administration
(properly configured).

Garp
Jul 17 '05 #12

P: n/a
Ken
Doesn't it say that phpMyAdmin must be installed in the root directory?

Ken

"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:K7*********************@news-text.cableinet.net...

"Ken" <kk******@wi.rr.com> wrote in message
news:RG*******************@twister.rdc-kc.rr.com...
<snip>
I was going to use phpmyadmin but the readme said the script must be in

the
root directory and I did not want it intermixed with my code.

<snip>

What? Where does it say that? That's not the case (why would it be?). You
might have read "root user" for the database and got it mixed up. I'm sure
it's installable anywhere you see fit.

I can't praise phpMyAdmin enough for day-to-day MySQL administration
(properly configured).

Garp

Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.