/    Sign up×
Community /Pin to ProfileBookmark

Archive.php not working

I tried everything, I’ll give all the code, should you require something more just tell me

Before the <head>

[code=php]<?php
if (empty($page)) {
$page = 0;
}
if (!empty($datesubmit)) {
if (empty($date)){
$date = $year.”-“.$month.”-“.$day;
}
}else{
$date = date(“Y-m-d”);
}
require(“NewsSql.inc.php”);
$db = new NewsSQL($DBName);
$searchresult = $db->getnewsbydate($page,$front_searchresultrecord,$date);

$PHP_SELF = $_SERVER[“PHP_SELF”];
?>[/code]

archive.php:

[code=php]<?php
print “$front_choosedate”;
dispselectdate();
?>

<?php
if (!empty($searchresult)) {
while ( list($key,$val)=each($searchresult) ) {
$title = stripslashes($val[“title”]);
$newsid = stripslashes($val[“newsid”]);
print “<a href=”news.php?newsid=$newsid” class=”en_b”>$title</a><br>”;
}
}
?><br>

<?php
$pagenext = $page+1;
$result1 = $db->getnewsbydate($pagenext,$front_searchresultrecord,$date);
if ($page!=0)
{
$pagepre = $page-1;
print “<a href=”$PHP_SELF?page=$pagepre&date=$date&datesubmit=$datesubmit”

class=”en_b”>$front_previouspage</a>&nbsp;&nbsp;&nbsp;&nbsp;”;
}
if (!empty($result1))
{
print “<a href=”$PHP_SELF?page=$pagenext&date=$date&datesubmit=$datesubmit”

class=”en_b”>$front_nextpage</a>”;
}
?>[/code]

the dispselectdate()

[code=php]
function dispselectdate()
{

global $front_searchsubmit;

$nowtimestamp = time();
$selecttimestamp = $nowtimestamp-86400;
$selectyear = date(“Y”,$selecttimestamp);
$selectmonth = date(“m”,$selecttimestamp);
$selectday = date(“j”,$selecttimestamp);

print “<form action=”$PHP_SELF” method=”POST”>
<select name=”year”>”;
for ($tempyear=2009;$tempyear<=2009;$tempyear++){
if ($tempyear==$selectyear){
print “<option value=”$tempyear” selected>$tempyear</option>”;
}else{
print “<option value=”$tempyear”>$tempyear</option>”;
}
}
print “</select>&nbsp&nbspYear&nbsp&nbsp”;

print “<select name=”month”>”;
for ($tempmonth=1;$tempmonth<=12;$tempmonth++){
if ($tempmonth==$selectmonth){
if ($tempmonth<10){
$tempmonth1 = “0”.”$tempmonth”;
}else{
$tempmonth1 = $tempmonth;
}
print “<option value=”$tempmonth1″ selected>$tempmonth1</option>”;
}else{
if ($tempmonth<10){
$tempmonth1 = “0”.”$tempmonth”;
}else{
$tempmonth1 = $tempmonth;
}
print “<option value=”$tempmonth1″>$tempmonth1</option>”;
}
}
print “</select>&nbsp&nbspMonth&nbsp&nbsp”;

print “<select name=”day”>”;
for ($tempday=1;$tempday<=31;$tempday++){
if ($tempday==$selectday){
if ($tempday<10){
$tempday1 = “0”.”$tempday”;
}else{
$tempday1 = $tempday;
}
print “<option value=”$tempday1″ selected>$tempday1</option>”;
}else{
if ($tempday<10){
$tempday1 = “0”.”$tempday”;
}else{
$tempday1 = $tempday;
}
print “<option value=”$tempday1″>$tempday1</option>”;
}
}
print “<select>&nbsp&nbspDay&nbsp&nbsp”;
print “<input type=”submit” name=”datesubmit” value=”$front_searchsubmit”>
</form>”;

}

?>
[/code]

The problem is, when put in a date and press search, the date form changes back to the 1st of january 2009 and outputs nothing.

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@dviper87authorJan 27.2009 — tried defining the $PHP_SELF

still not working though
Copy linkTweet thisAlerts:
@SyCoJan 28.2009 — First thing to do when you have a problem is set
[code=php]
error_reporting(E_ALL);[/code]


at the top of your script. You'll get the error messages you need to debug the problem.

Try this instead of $PHP_SELF
[code=php]$_SERVER['SCRIPT_NAME'][/code]
Copy linkTweet thisAlerts:
@dviper87authorJan 28.2009 — error reporting:

Notice: Undefined variable: PHP_SELF

Fixed the undefined variable by adding

$PHP_SELF = $_SERVER["PHP_SELF"];

however, the script still doesn't output the wanted result, namely the posts on the selected day...
Copy linkTweet thisAlerts:
@SyCoJan 28.2009 — error reporting:

Notice: Undefined variable: PHP_SELF

Fixed the undefined variable by adding

$PHP_SELF = $_SERVER["PHP_SELF"];

however, the script still doesn't output the wanted result, namely the posts on the selected day...[/QUOTE]


Why do this?
[code=php]
$PHP_SELF = $_SERVER["PHP_SELF"];[/code]


Why not just use $_SERVER["PHP_SELF"]

[code=php]print "<form action="".$_SERVER["SCRIPT_NAME"]."" method="POST">[/code]

Also why did you use

$_SERVER["PHP_SELF"] instead of the suggested $_SERVER["SCRIPT_NAME"]

If you have a good reason please share. AFAIK $_SERVER["PHP_SELF"] is more portable but apparently more vulnerable to XSS attacks.
Copy linkTweet thisAlerts:
@dviper87authorJan 28.2009 — I replaced all the $PHP_SELF by ".$_SERVER["SCRIPT_NAME"]."

but the script still doesn't output anything...
Copy linkTweet thisAlerts:
@SyCoJan 28.2009 — Add this to a new blank file and hit submit
[code=php]
<?
print_r($_POST);
?>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">
<input type="hidden" id="test" name="test" value="posted value">
<input type="submit">
</form>[/code]


It should output this after submit
[CODE]Array
(
[test] => posted value
)[/CODE]


View the page source. The action of the form should be the script name.
Copy linkTweet thisAlerts:
@dviper87authorJan 28.2009 — The script is on archive.php

So in theory it must be "/archive.php"

EDIT: as can be seen at my first post, the dispselectdate() function is on a seperate file, which is required. This script also contains the $_SERVER['SCRIPT_NAME'] apart from the archive.php which contains it twice. Should I change all three to "/archive.php"?
Copy linkTweet thisAlerts:
@SyCoJan 28.2009 — 
So in theory it must be "/archive.php"
[/QUOTE]

In theory? What theory? You have a variable and a value echoed out no theory.

[code=php]echo $_SERVER['SCRIPT_NAME'];[/code]

What do you get?
Copy linkTweet thisAlerts:
@dviper87authorJan 28.2009 — If I put it on a blank file I get:

action="/how-I-name-the-file.php"
Copy linkTweet thisAlerts:
@SyCoJan 28.2009 — This feels like pulling teeth.

What is the result of posting the form as suggested back in post #7?
Copy linkTweet thisAlerts:
@dviper87authorJan 29.2009 — view source:
[CODE]Array
(
[test] => posted value
)
<form method="post" action="">
<input type="hidden" id="test" name="test" value="posted value">
<input type="submit">
</form> [/CODE]
Copy linkTweet thisAlerts:
@SyCoJan 29.2009 — In post 10 you get
[CODE]action="/how-I-name-the-file.php" [/CODE]
but this
[code=php]<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']?>">[/code]
Give you a blank action? I don't see how that is possible.
Copy linkTweet thisAlerts:
@dviper87authorJan 29.2009 — I'm sorry for not fully understanding, but I'm trying.

The output after action depends on how I name the blank file. Does that answer it?
Copy linkTweet thisAlerts:
@SyCoJan 29.2009 — If you skip information n your posts and edit what you actually get, how can anyone help.

I feel like I'm wading through syrup uphill here. A simple form test to check you server configuration has taken 7 more posts and we're still not there in post #15.

Did you clear the action out of the form yourself or is it not displaying? If you cleared it out why would you do that and not say. I'm not telepathic, I think you need someone to help who is.

Having the same form reload onto itself intentionally using the same variable names is not they way to write code. I think you need to redesign your interface and rethink the logic.

Good luck with you problem, I don't think I can help you further.
×

Success!

Help @dviper87 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...