473,472 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Database

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
12 1900
"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
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
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
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
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
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
6
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database...
8
by: Kamlesh | last post by:
Hi, How do I know the physical database path of a database. When I goto the DB2INSTANCE users's directory (/home/db2inst1), I see following folders: /db2inst1/NODE0000/SQL00001...
1
by: pintur | last post by:
The message is: SQL1036C Errore di I/O durante l' accesso al database. SQLSTATE=58030 what is the proble? what for restore tables? thanks
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
8
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well....
0
by: Jack | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available....
0
by: Winder | last post by:
Training Classes for Oracle10g, 9i, 8i Certification training in Oracle10g and 9i: DBA, Developer, Discoverer. training conducted at your location worldwide. Courseware licensing also available....
0
by: Laurynn | last post by:
# (ebook - pdf) - programming - mysql - php database applicati # (Ebook - Pdf)Learnkey How To Design A Database - Sql And Crystal Report # (ebook-pdf) E F Codd - Extending the Database Relational...
9
by: Peter Duniho | last post by:
Is there a straightfoward API in .NET that allows for inspection of a database? That is, to look at the structure of the database, without knowing anything in advance about it? For example,...
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
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...
1
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.