472,954 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Stale data when requerying MySQL w/PHP?

I've got this weird problem. I'm connecting to MySQL via PHP,
querying a particular table, closing the connection then parsing and
displaying the results. I then modify the table but when I reload the
PHP page, the output does not reflect this change.

Viz:

----[SQL query]----
mysqlselect * from users;
+----------+
| username |
+----------+
| jayds |
+----------+

----[web page output]----
Array ( [username] =jayds )

----[SQL query]----
mysqlinsert into users values ("wes");
Query OK, 1 row affected (0.00 sec)

----[reloaded web page output]----
Array ( [username] =jayds )

....and a rechecking of the db reflects that "wes" IS, in fact, in the
table.

This is the code I'm using (minus the parts that parse and print the
resource):

----[%begin%]----

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');

mysql_select_db('wes') or die('Could not select database');

$query = "SELECT * FROM users";
$resource = mysql_query($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

----[%end%]----

Any ideas on why I'm seeing stale data?

Thanks much in advance!,
Jason
Sep 28 '08 #1
4 2313
bodhiSoma wrote:
I've got this weird problem. I'm connecting to MySQL via PHP,
querying a particular table, closing the connection then parsing and
displaying the results. I then modify the table but when I reload the
PHP page, the output does not reflect this change.

Viz:

----[SQL query]----
mysqlselect * from users;
+----------+
| username |
+----------+
| jayds |
+----------+

----[web page output]----
Array ( [username] =jayds )

----[SQL query]----
mysqlinsert into users values ("wes");
Query OK, 1 row affected (0.00 sec)

----[reloaded web page output]----
Array ( [username] =jayds )

...and a rechecking of the db reflects that "wes" IS, in fact, in the
table.

This is the code I'm using (minus the parts that parse and print the
resource):

----[%begin%]----

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');

mysql_select_db('wes') or die('Could not select database');

$query = "SELECT * FROM users";
$resource = mysql_query($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

----[%end%]----

Any ideas on why I'm seeing stale data?

Thanks much in advance!,
Jason
Caching - either by your browser or a system between your web server and
your client?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 28 '08 #2
bodhiSoma wrote:
I've got this weird problem. I'm connecting to MySQL via PHP,
querying a particular table, closing the connection then parsing and
displaying the results. I then modify the table but when I reload the
PHP page, the output does not reflect this change.

Viz:

----[SQL query]----
mysqlselect * from users;
+----------+
| username |
+----------+
| jayds |
+----------+

----[web page output]----
Array ( [username] =jayds )

----[SQL query]----
mysqlinsert into users values ("wes");
Query OK, 1 row affected (0.00 sec)

----[reloaded web page output]----
Array ( [username] =jayds )

...and a rechecking of the db reflects that "wes" IS, in fact, in the
table.

This is the code I'm using (minus the parts that parse and print the
resource):

----[%begin%]----

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');

mysql_select_db('wes') or die('Could not select database');

$query = "SELECT * FROM users";
$resource = mysql_query($query) or die('Query failed: ' .
mysql_error());
mysql_close($conn);

----[%end%]----

Any ideas on why I'm seeing stale data?

Thanks much in advance!,
Jason
You performed an INSERT not an UPDATE.

Could it be that you have both entires in your DB and only viewing one
of them retrieved?

The code you show is incomplete so its hard to tell.

If you follow the code you have with:

while($user = mysql_fetch_array($resource)) {
echo $user[username]."<br>";
}

Will it show the only one entry?

Also not sure if this is in your actual code or just typed it wrong in
here but:

$resource = mysql_query($query) or die('Query failed: ' .

is missing the last )

Scotty

Sep 28 '08 #3
On Sep 28, 5:27*pm, FutureShock <futuresho...@att.netwrote:
Could it be that you have both entires in your DB and only viewing one
of them retrieved?
That was precisely it. Thanks!!

Jason
Sep 29 '08 #4
bodhiSoma wrote:
On Sep 28, 5:27 pm, FutureShock <futuresho...@att.netwrote:
>Could it be that you have both entires in your DB and only viewing one
of them retrieved?

That was precisely it. Thanks!!

Jason
Glad to help. Don't be a stranger.

Scotty
Sep 29 '08 #5

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

Similar topics

0
by: Jeff Nokes | last post by:
Hello, I'm using Cache::SharedMemoryCache with an Apache 1.3.28 / mod_perl 1.28 / Mason instance on RedHat Linux 7.2. The caching mechanism seems to work fine, it creates one shared memory...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
1
by: Chicken Kebab Abdullah | last post by:
I am making a database of my movie collection and I have a form which Shows a DVD Code in a combo, and a list of the divx movies on the dvd on the right in a list box. The combo boxes bound...
1
by: John Rivers | last post by:
Hello, This topic has bugged me for years. The ideal for handling web forms would be that submitting the form replaces the browser history's current url with the url resulting from the form...
9
by: Michael | last post by:
Hi, I have a large table. Normally, the user will need to see only the data from the past two years, but sometimes, they will need to go back further. I have a form with a datagrid, a...
3
by: petermichaux | last post by:
Hi, I am trying to put together the last major pieces of my project's puzzle. This is more website/client-side architecture than JavaScript syntax but I hope this is a good place to ask. I'm a...
2
by: Ulrike Klusik | last post by:
Hello Folks, i've got two structural identical tables (including tablespace and indexes) with identical data, on which the access path of an SQL is differs. But I don't see a reason for the...
2
by: paula | last post by:
I have a front-end access database that uses a sql server back-end to link the tables. When I run the following code, the subform displays #deleted in place of the deleted record. What am I doing...
1
by: bkberg05 | last post by:
Hi -I have a form which contains a sub-form. The sub-form is tied to the main form by a shared field called Project_ID. The main form has one record per Project. The sub-form has many records per...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.