/    Sign up×
Community /Pin to ProfileBookmark

content switch

Anybody with suggestion on what am i doing wrong here (probably a lot, total newb in php):
In the form tag i have:
<form name=”form” action=”index.php?s=1″ method=”post”>
<input type=”text” name=”q” … etc
in the center <div> i have:
<?php
if($_GET[‘s’]==1) {
$file =”search.php?q=” . $_
POST[‘q’];
include($file);
break;
} else {…. etc switch cases for a menu)
and the php part in search.php starts with
$var = @$_GET[‘q’] ;
What i’m trying to do is open the results from the search form from search.php in the <div> where the switch cases are. Switch cases works, the search.php opens fine if its pointed to a _
blank from the form. And when i submit the form, the browser goes to index.php?s=1, but nothing loads. How can i do that differently or what am i doing wrong?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NanscombeNov 22.2007 — Hi Dali,

How about something like:-


<form name="form" action="index.php?s=1" method="post">

<input type="text" name="q" ... etc

...

...

</form>
[/quote]



<div>

<?php


if($_REQUEST['s']==1) {[INDENT]$file = '';

if(isset($_
REQUEST['q'])) $file = $_REQUEST['q'];

if ($file != '') @include($file);


[/INDENT]}

?>

</div>
[/quote]


I've use $_REQUEST because this looks at both the $_GET and the $_POST parameters.

Regards

Nigel
Copy linkTweet thisAlerts:
@DaliauthorNov 22.2007 — Still nothing (fixed the missing {} around), but same result.
Copy linkTweet thisAlerts:
@DaliauthorNov 22.2007 — or wait, where would the search.php get in the picture in your version?
Copy linkTweet thisAlerts:
@TecBratNov 23.2007 — what am i doing wrong?[/QUOTE]
As far as I can tell, the only error is here:"$var = @$_GET['q'] ;" make it "$var = @$_POST['q'] ;" and it should work. This is very simliar to how I do my forms.
Copy linkTweet thisAlerts:
@NanscombeNov 23.2007 — Hi Dali,

if(isset($_REQUEST['q'])) $file = $_REQUEST['q'];[/quote]

This would set the variable [B]$file[/B] to whatever the value of [B]q[/B] would be, ie if [B]q=example1[/B] then it would include the file [B]example1[/B] from the same directory as the webpage.

If you need something more complex then you could use something like:-

if(isset($_REQUEST['q'])) $file = '/images/' . $_REQUEST['q'] . '.jpg';[/quote]

Using the same [B]q=example1[/B], [B]$file[/B] would then become [B]/images/example1.jpg[/B]

If you were using this to include an image then if ($file != '') @include($file);[/quote] would become if ($file != '') echo '<img src = "' . $file . '">';[/quote]

Regards

Nigel
Copy linkTweet thisAlerts:
@DaliauthorNov 24.2007 — Sorry, my fault, was a bit short on the explaining, the form is a search form as in searches for products in database. So what i need it to do is let search.php process the form, and show results in the <div> where the switch cases are. (form is in a different <div>).

Making is make it "$var = @$_POST['q']; in the search.php didn't help, i don't think it even tryes to process search.php.
×

Success!

Help @Dali 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 5.15,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...