/    Sign up×
Community /Pin to ProfileBookmark

hi can anyone help me?just a simple one..

Hi i wrote this code
<HTML>
<form>
<select>
<option>Yes</option>
<option>No</option>
</select>
<input type=”submit” value=”ok”/>
</form>
</HTML>
now i want to add something inside.
when my option is yes and i click ok button, the array $book=’English.php’ while if my option is no and click on summit button the array $book=’German.php’
how could i make it?
plz help…im urgent…

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@gogelpotNov 21.2006 — Does your script have to redirect the browser to either English.php or German.php. Or is it the value of $book that you want to set before submitting (passing the value of $book) it to another PHP file.
Copy linkTweet thisAlerts:
@coppocksNov 21.2006 — Hi i wrote this code

<HTML>

<form>

<select>

<option>Yes</option>

<option>No</option>

</select>

<input type="submit" value="ok"/>

</form>

</HTML>

now i want to add something inside.

when my option is yes and i click ok button, the array $book='English.php' while if my option is no and click on summit button the array $book='German.php'

how could i make it?

plz help...im urgent...[/QUOTE]

First you need to name the Select...

<i>
</i>&lt;HTML&gt;
&lt;form method = "post" value="myScript.php"&gt;
&lt;select Name="Book"&gt;
&lt;option&gt;Yes&lt;/option&gt;
&lt;option&gt;No&lt;/option&gt;
&lt;/select&gt;
&lt;input type="submit" value="ok"/&gt;
&lt;/form&gt;
&lt;/HTML&gt;


Then your php code would be something like this...

<i>
</i>&lt;?
if (isset($_POST['Book'])) {
// you may need/want to set the variable first...
$book = '';
if ($_POST['Book'] == 'Yes') {
$book='English.php';
}
else {
$book='German.php';
}
}
?&gt;


Now if you're trying to go to one of those pages depending on which one is selected... try this...

<i>
</i>
&lt;?
// assuming this page is named test.php
if (isset($_POST['Book'])) {
// you may need/want to set the variable first...
$book = '';
if ($_POST['Book'] == 'Yes') {
$book .= 'English.php';
}
else {
$book .= 'German.php';
}
header('Location: http://www.yourURL.com/' . $book);
}
?&gt;
&lt;HTML&gt;
&lt;form method = "post" value="test.php"&gt;
&lt;select Name="Book"&gt;
&lt;option&gt;Yes&lt;/option&gt;
&lt;option&gt;No&lt;/option&gt;
&lt;/select&gt;
&lt;input type="submit" value="ok"/&gt;
&lt;/form&gt;
&lt;/HTML&gt;

Copy linkTweet thisAlerts:
@theRamonesNov 21.2006 — <select name="book">

<option value="English.php">Yes</option>

<option value="German.php">No</option>

</select>
Copy linkTweet thisAlerts:
@teongkiaauthorNov 21.2006 — to gogelpot:

i dun need to redirect the script just to set the array $book to English or German when i click ok button..any idea for this?thanks..

to Coppocks:

coppocks i tried on your code how come when i click ok button there is nothing happen?is it once i click ok button then the $book will be set to what i chose permanently?

another question is i have another file called book1.php which has $book inside.is it when i click ok button the $book in my book1.php will be set too if i add <?php require_once('myscript.php');?> at the top page?thanks a lot...

to theramones:

thanks lot too...
Copy linkTweet thisAlerts:
@gogelpotNov 21.2006 — I think "theRamones" gave you the answer.
Copy linkTweet thisAlerts:
@teongkiaauthorNov 22.2006 — Hi let me explain in detail on what i want.Actually im a trainee and my boss ask me to create a program.The company is

selling a website which provides 8 services.What my boss ask me to do is create a program where i can choose yes or no

for each service and when go into the website i would not able to click on those link which i selected no.For example

there are 8 language services english,german and so on.when i click no for german and the other click ok.after i click

submit button,the array will be set and when i go into the website and when i click on german link, it will link to service is

not available page.For example the service is not available page i save as notavailable.php and german page is

german.php.On the main page of website i save it as index.php.so i set all those services to array such as

$english,$german and so on.how can i make it that when i click no on german, the $german='noservice.php' and when i click

yes the $german="german.php'.hope u understand my idea...and help me out...thanks..
Copy linkTweet thisAlerts:
@AmazingAntNov 22.2006 — Ok, lets see here...

...is it once i click ok button then the $book will be set to what i chose permanently?...[/quote]
No, the variable $book will not exist after the page finishes loading.

As for the rest of it,

have the form send it's information to a file with this code, making sure that you name the select portion of the form "language".
[code=php]
<?php
if (isset($_POST['language']){
setcookie("language", $_POST['language'], time()+60*60*24*365);
}
?>
[/code]

That will set a cookie on the client's machine, with the language they selected in it.

And then for your main page on the german service, do like so:
[code=php]
<?php
if (isset($_COOKIE['language'])){
$redir = "Location: http://www.Website.com/german.php";
if ($_COOKIE['language'] != "german"){
$redir = "Location: http://www.Website.com/noservice.php";
}
header($redir);
}
?>
[/code]


Does that work?
Copy linkTweet thisAlerts:
@teongkiaauthorNov 22.2006 — example code in index.php

<a href="$german" class="link"><img src="../frontpage-admin/images/admin_home_facilities.gif" border="0">

the $german will be set when i click yes or no..

how should i do it in the option list file...
Copy linkTweet thisAlerts:
@teongkiaauthorNov 22.2006 — Hi AmazingAnt..didnt u read the long statement i wrote?i was thinking if i use session i can set it for any period i like but is it better if i use database to store what i selected and retrieve the array i store using from MySQL?do u think this is better way?

thanks...
Copy linkTweet thisAlerts:
@sb_Nov 22.2006 — Your language files.
<i>
</i>$book = {"english" =&gt; "german",
"etc" =&gt; "etc"};



You're page with the language change.
<i>
</i>include(''.$language.'.php');
// ....
Copy linkTweet thisAlerts:
@AmazingAntNov 22.2006 — Hi AmazingAnt..didnt u read the long statement i wrote?i was thinking if i use session i can set it for any period i like but is it better if i use database to store what i selected and retrieve the array i store using from MySQL?do u think this is better way?

thanks...[/QUOTE]
If you can work with MySQL, the yes, that would be a better way. You must remember that there is no way to permanantly track a user however, since their IP address can change, they can remove cookies, etc..

And yes, I did read it. I've read everything in this thread. Some of it is just a little hard to understand. You don't exactly have perfect English skills.
<a href="$german" class="link"><img src="../frontpage-admin/images/admin_home_facilities.gif" border="0">

the $german will be set when i click yes or no..[/QUOTE]

No, that won't set it. If you want it to set to yes when you click on an image for german, then it will need to be like this: href="next-page.php?lan=german" and then use the other page to find out what $_GET['lan'] is, and then set everything in MySQL however you need it.
Copy linkTweet thisAlerts:
@teongkiaauthorNov 23.2006 — oh thanks lot Ant, i think i get it..maybe will need your help soon..thanks lot...
×

Success!

Help @teongkia 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.18,
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,
)...