teongkia Posted November 21, 2006 Share Posted November 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... Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/ Share on other sites More sharing options...
jawapro Posted November 21, 2006 Share Posted November 21, 2006 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] etcNow 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 Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-127812 Share on other sites More sharing options...
teongkia Posted November 21, 2006 Author Share Posted November 21, 2006 thanks jawapro i tried on the codeis 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.. Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-127825 Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 I wrote that all off the top of my head - sorry for any errors.action='myphpscript.php' is completely correct. Sorry I forgot the .phpYou 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.htmlWhen 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 Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128240 Share on other sites More sharing options...
teongkia Posted November 22, 2006 Author Share Posted November 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.. Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128256 Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 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....<?phpif (){echo "<a href='german.php'>German</a>";}else{echo "<a href='notavailable.php'>German</a>";}?>...HTML[/quote]Does that help??? Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128262 Share on other sites More sharing options...
teongkia Posted November 22, 2006 Author Share Posted November 22, 2006 let's say in index.php i got this code echo "<a href='$German'>German[/url]";$German='German.php' or $German='notavailable.php' is set using the option list u shown me...how could i make it?thanks.. Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128298 Share on other sites More sharing options...
jawapro Posted November 22, 2006 Share Posted November 22, 2006 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. Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128346 Share on other sites More sharing options...
teongkia Posted November 22, 2006 Author Share Posted November 22, 2006 oh thanks javapro at least i know some very basic..i will learn more and soon will question u again...thanks lot...hear from u soon... Link to comment https://forums.phpfreaks.com/topic/27936-hi-can-help-me-outjust-a-simple-one/#findComment-128379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.