Jump to content

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


teongkia

Recommended Posts

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...
Link to comment
https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/
Share on other sites

You need to give your select a name, and some values.

For Example:
[code]<select name='myselector'><option value='yerpo'>Yes</option><option value='noway'>No</option><option value='maybeish'>Maybe</option></select>[/code]

That way you can use PHP to talk to it. You also need to change your <form> tag so it points to some PHP script.

[code]<form action='myphpscript' method='post' name='whatever'>[/code] etc

Now in myphpscript...

[code]<?php
$yesorno = $_POST['myselector'];

if ($yesorno == 'yerpo')
{
$book='English.php';
}

if ($yesorno == 'noway')
{
$book='German.php';
}

if ($yesorno == 'maybeish')
{
$book='Klingon.php';
}
[/code]

See if that helps you.

Jawa
thanks jawapro i tried on the code
is it <form action='myphpscript' method='post' name='whatever'> should be action='myphpscript.php'?
is it i have to add <input type="submit" value="ok"/> in order for me to click ok and set the array to what i want?
another question is i have to link to another file which is book1.php where the $book is to be set in book1.php also.is it the top page i have to type <?php require_once('myphpscript.php');?>  ?
then the array is set when i click ok button?
thanks..
I wrote that all off the top of my head - sorry for any errors.


action='myphpscript.php' is completely correct. Sorry I forgot the .php


You need a submit button to submit the form. So <input type="submit" value="ok"/> would work fine.

I am afraid I dont understand [quote]another question is i have to link to another file which is book1.php where the $book is to be set in book1.php [/quote] Can you explain the question more so I can understand it please.

And for the last question, you dont NEED to include the myphpscript.php in the first page. The first page could be called anything you want. It can be either HTML of PHP. Lets just say we call it fred.html

When you click the 'ok' submit button, it goes and sends the information from the form to the script specified in the action field. In this case myphpscript.php. That script can now do whatever you need it to with the values from the field.

Hope I've been Helpful.

JP
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..

Somewhere you'll want to store the values (probably in a database or something). When you go to index.php you can read the values and then use them.

[quote]...HTML Code....
<?php
if ()
{
echo "<a href='german.php'>German</a>";
}
else
{
echo "<a href='notavailable.php'>German</a>";
}
?>
...HTML[/quote]

Does that help???
Far as I know that should work.

The echo "<a href='$German'>German</a >"; part anyway.

But in THAT file you need to have a $German = whateveritdoes; statement before that echo line.

So something like
[code]
$yesorno = $_POST['myselector'];
if ($yesorno == yes)
{
$German = 'german.php';
}
else
{
$German = 'notavailable.php';
}[/code]

Or something where it gets the data into $German.

But the echo code should work fine. Did on my server when I tried it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.