...

View Full Version : problem



g0liatH
11-12-2003, 04:46 PM
I made a script:



<form>
<SELECT name="test">
<OPTION value="1">1</OPTION>
<OPTION value="2">2</OPTION>
<OPTION value="3">3</OPTION>
</SELECT><BR></form>




<? if ($_POST['test'] = 2 ) {

$template = "ATGtemp";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
else {
echo "testtest";
}
?>


these 2 codes are in 1 file.

I always get include() and I never get "testtest"
What do I have to change in the script so it wont always show include() ???

mordred
11-12-2003, 05:11 PM
if ($_POST['test'] = 2 )


is most certainly a typo. What you are doing there is assigning the number 2 to $_POST['test'] by using one equals sign. This assignment always succeeds, so it evaluates as true. What you need is to use two equals signs to compare for equality:



if ($_POST['test'] == 2 )


If you happen to make this mistake often, here's a trick that works the same as the above code, but if you use one equals sign you get a PHP error:



if (2 == $_POST['test'])

Spookster
11-12-2003, 05:12 PM
I'm not sure how you even get that. Your expression in your if statement is incorrect

if ($_POST['test'] = 2

should probably be

if ($_POST['test'] == "2")

mordred
11-12-2003, 05:13 PM
And if you define your form tag without the method="post" attribute, all incoming form data will be by GET, and thus in the $_GET array.

g0liatH
11-12-2003, 05:14 PM
ok thx guys :thumbsup: I kno im a n00b :o

g0liatH
11-12-2003, 05:44 PM
I used the script now and it works but there is still 1 problem.
If i click "post comment", the script goes back to the first page:confused:

you can see it yourself here:
http://www.alltimegaming.com/phptest/testform2.php
and if I click the submit button again, it works...

this is the new code:


<form method="post">
<SELECT name="test">
<OPTION value="1">Show All</OPTION>
<OPTION value="2">General</OPTION>
<OPTION value="3">Gaming</OPTION>
<OPTION value="4">Site</OPTION>
<OPTION value="5">Events</OPTION>
</SELECT><BR>
<input type="submit" value="Submit">
</form>
<? if ($test == 1 ) {
$template = "ATGtemp";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
elseif ($test == 2 ) {
$template = "ATGtemp";
$category= "3";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
elseif ($test == 3 ) {
$template = "ATGtemp";
$category= "4";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
elseif ($test == 4 ) {
$template = "ATGtemp";
$category= "5";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
elseif ($test == 5 ) {
$template = "ATGtemp";
$category= "6";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}

?>


Do u know what the problem is? Is there a else {} command to continue the link?

Nightfire
11-12-2003, 06:01 PM
<form method="post">
<SELECT name="test">
<OPTION value="1">Show All</OPTION>
<OPTION value="2">General</OPTION>
<OPTION value="3">Gaming</OPTION>
<OPTION value="4">Site</OPTION>
<OPTION value="5">Events</OPTION>
</SELECT><BR>
<input type="submit" value="Submit">
</form>
<?php

$test = $_POST['test'];

if ($test == 1 ) {
$template = "ATGtemp";
include("/home/virtual/site51/fst/var/www/html/news2/show_news.php");
}
..... etc etc etc ..........

g0liatH
11-12-2003, 06:06 PM
It doesn't help. I still have to click submit until I can post a comment

Nightfire
11-12-2003, 06:15 PM
I dunno where your problem is, I don't even see a post comment on that form or code you're showing

g0liatH
11-12-2003, 06:25 PM
if you click on gaming or show all or whatever, you see news, and on every newspost u see "comments", if you click on that, you just go to a white page instead of the page u should go and if u then click submit, u go to the real page.

mordred
11-12-2003, 06:28 PM
If you mean by "Post Comment" the link titled "comments", then you get the data per GET parameters. Links are not forms and their query string does not appear in the $_POST array. Does that help?

g0liatH
11-12-2003, 06:30 PM
yea i mean the link "comments". so u are saying I have to change
<form method="post"> to <form method="get">
?

g0liatH
11-12-2003, 08:11 PM
w00t finally it works!!:D

thx everyone who helped me:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum