473,671 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange PHP/MySQL behavior

I am working with the following script for a weblog that manipulates any
combination of two variables: $postauthor and $archive.

if (isset($HTTP_GE T_VARS['archive'])) {
$archive = $HTTP_GET_VARS['archive'];
if (strlen($archiv e) > 15) {
die("Sorry, the system cannot process your request. Please contact the
webmaster.");
}
} elseif ((isset($HTTP_P OST_VARS['archive'])) &&
($HTTP_POST_VAR S['archive'] != "")) {
$archive = $HTTP_POST_VARS['archive'];
$archive = str_replace("_" , " ", $archive);
}

if ((isset($HTTP_P OST_VARS['author'])) && ($HTTP_POST_VAR S['author'] !=
"")) {
$postauthor = $HTTP_POST_VARS['author'];
}

if ((isset($archiv e)) && (strlen($archiv e) == 4)) {
include "./archives/$archive.php";
} else {
if ((isset($archiv e)) && (isset($posauth or))) {
$postquery = "select authors.name, posts.postid, posts.date,
posts.time, posts.subject, posts.text
from authors, posts
where authors.authori d = posts.authorid
and posts.date like '%".$archive. "'
and authors.name = '".$author." '";
} elseif (isset($archive )) {
$postquery = "select authors.name, posts.postid, posts.date,
posts.time, posts.subject, posts.text
from authors, posts
where authors.authori d = posts.authorid
and posts.date like '%".$archive."' ";
} elseif (isset($postaut hor)) {
$postquery = "select authors.name, posts.postid, posts.date,
posts.time, posts.subject, posts.text
from authors, posts
where authors.authori d = posts.authorid
and authors.name = '".$author." '";
} else {
$postquery = "select authors.name, posts.postid, posts.date,
posts.time, posts.subject, posts.text
from authors, posts
where authors.authori d = posts.authorid
order by posts.postid desc
limit 10";
}
getPosts($postq uery);
}
The variables are assigned via drop-down menus. Each menu has an option
whose value is "".

This all works very well. The first time the page loads it recognizes
that neither variable is set and does the appropriate thing. Setting
either or both of the variables returns the correct items as well.
However, if you load the page, set neither variable, and click "Go" it
returns every post in the database (only 2 months) in ascending order.

When I echo the query it is using, I find that it is using the query as
though $archive were set, and coming up with the string:
"select authors.name, posts.postid, posts.date, posts.time,
posts.subject, posts.text
from authors, posts
where authors.authori d = posts.authorid
and posts.date like '%'"

Thus the behavior is expected, but I don't understand why the script
acts as though $archive had some value, or why the same problem never
occurs with $postauthor despite being set by an almost equivalent
statement, or why it works correctly the first time the page loads! As
you can see, when the value "" is chosen, the script is told not to
assign any value to the corresponding variable.

This behavior can be observed at http://www.digitalovertone.com/weblog/

Many thanks,

Kyle
Jul 17 '05 #1
2 1561
So, ignoring the misspelled variable 'posauthor' (which breaks something
else and is now fixed), I have corrected this the long way. The problem
occurred on my web-hosting server, but not on my localhost. I would
still be interested in know why the variable ever gets set on my server,
if anyone can explain.

Thanks,

Kyle
Jul 17 '05 #2
Kyle James Matthews wrote:
[snip]
Thus the behavior is expected, but I don't understand why the script
acts as though $archive had some value, or why the same problem never
occurs with $postauthor despite being set by an almost equivalent
statement, or why it works correctly the first time the page loads! As
you can see, when the value "" is chosen, the script is told not to
assign any value to the corresponding variable.


Looks like you have register_global s on: when an empty 'archive'
parameter is submitted in the form posting, the global variable $archive
is set to "". This is ignored by your first if statement, so the later
check for isset($archive) comes up true.

-- brion vibber (brion @ pobox.com)
Jul 17 '05 #3

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

Similar topics

4
1871
by: Bruce A. Julseth | last post by:
My MySQL.user table (user, host, password) looks like the following: +---------+-----------+---------------------+ | user | host | password | +---------+-----------+---------------------+ | root | localhost | | | root | % | | | | localhost | 3823a5ee1f831626 | | | % |...
2
3445
by: Marcus | last post by:
Hello, I recently converted all my existing MyISAM tables to InnoDB tables through phpmyadmin. I noticed some strange behavior whenever I would refresh the screen, as phpmyadmin would report different numbers for the cardinality of the primary key (i.e. one minute it would say cardinality 388, then 244 on refresh, then something else), and it would report different values for the number of rows when mousing over the table names on the...
0
1127
by: David Emme | last post by:
Win XP Pro Access 97 MySQL 4.0.x I'm attempting to convert a number of apps to MySQL backends. Having converted the tables from the MDB backend, I'm running into a number of differences in behavior between the app using the MDB backend and that using the MySQL backend. Several problems seem to boil down to the following: A "Single Form"
1
1947
by: Default | last post by:
Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is VS files corrupted , or something else. that is the problems description: I am working on a small database project. I am not using any data sources Mysql, access etc. Instead I use binary formatter to store and read data. at the beginning the program checks username/password. it does it in the following way: if(form2.initialized) { for(int i=0;...
1
1789
by: Dennis Kuntzemann | last post by:
Hello, I am trying to get access to an MySql-Server over CSharp. As I am not sure whether it is an csharp or sql driver problem, i am posting it here. I got the following error: PM Exception: Object reference not set to an instance of an object. 6/27/2006 12:23:25 PM Stack trace: at MySql.Data.MySqlClient.PacketWriter.WriteStringNoNull(String v)
2
2601
by: Curtis | last post by:
Hello everyone: I have come to love the ease of updating PHP, since getting used to using it these past few years. Recently, however, when I upgraded from PHP 5.1 to PHP 5.2.0 and again when moving to 5.2.1, I noticed strange behavior when trying to load php_mysqli.dll. I am using Apache 2.2.3 on Windows XP Pro (32-bit). I use the php5apache2_2.dll to load PHP as an Apache module. The PHPIniDir directive in httpd.conf points to the...
5
1608
by: Marcel Molenaar | last post by:
Anyone ever experienced this problem. When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected too. That is not right i think because my result inside my class is private. Is this a bug? Can someone look at my code below please: <?php require_once('includes/connect.php');
0
1178
by: Marcel Molenaar | last post by:
Anyone ever experienced this problem. When i pass a mysql result to the constructor of a class and use that resultset inside that class the original resultset outside the class gets affected too. That is not right i think because my result inside my class is private. Is this a bug? Can someone look at my code below please: <?php require_once('includes/connect.php');
2
1586
by: KDawg44 | last post by:
Hi, I have the following code: $resultSet = mysql_query($sqlString); $numResults = mysql_num_rows($resultSet); echo "Num Results = " . $numResults . "<br/>"; for ($i = 0; $i < $numResults; $i++) { $row = mysql_fetch_array($resultSet); echo "i = " . $i . "<br/>";
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4221
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
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 we have to send another system
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.