Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am a newbie PHP devloper and i want to implement an online examination system. I want to implement a system which asks one question at a time i.e after answering 1st question click newxt then 2nd question will be displayed. how to implement this? do i have to implement through sessions? I am using loop but loop displays 20 questions one after another plzz help.
A very easy way to do this would be to implement a html structure that is the same for each questions.
In php, at the beginning of the page, you just check for the post data, if there's none, then you load the first question ( in database, or hardcodded, as you wish ).
If there's post data, you check if the question id is there, save the answer for the user, and load the next question.
It would look a bit like that:
<?php
function loadQuestion($id){
//your logic to load the question
return $question;
}
function saveAnswer($id,$answer){
//your logic to save the answer
}
if($_POST){
saveAnswer($_POST['id_question'],$_POST['answer'])
$data = loadQuestion($_POST['id_question']+1);
}
else $data = loadQuestion(1); //first question
?>
<form method="POST">
<input type="hidden" name="id_question" value="<?php echo $data["id_question"]; ?>" />
<div class="questionDiv">
<?php echo $data["question"]; ?>
</div>
answer:
<input type="text" value="" name="answer" />
<input type="submit" value="send" />
</form>
You could use sessions, yes. Using sessions would allow you to write all of your questions and everything in a single page, and then you could use a switch/case block to pump out the right question within the page. Use the post method on the form, and at the top of your page, check if the post is set, push the data into the correct mysql statement if so, and display the next question question (based on a session variable).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
lets say i have $x data that has posted from another page to my currentpage. and i want to get additional input information from user, and post both of these datas to the next page. how would i do that? i tried to give posted data as a name attribute to button but i cant get them from nextpage
as an example here my current page;
please check it here
here $x came from first page as a posted data. and i will have one more data named="mesai". and i want to access these two in the nextpage. thats why i tried to name button as $x but it didnt work.
hope you understand what i mean. thanks
Use always code format not image for your question.
An option you can use hidden value like:
<input id="howuwant" name="howuwant" type="hidden" value="<?php echo $_POST['howuwant'] ?>">
or if you are in php page
echo " <input id='howuwant' name='howuwant' type='hidden' value='".$_POST['howuwant']."'>;
Now you have all two data for the next page.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a vanilla PHP directory comprising of queried MySQLi information but I want to make it so that on the press of a button it would dynamically take the information from whatever button I clicked and populate the a redirect page with that information.
The problem being, no matter where I look I can't figure out how to achieve that, $_GET & $_POST don't seem to be the way to go, any pointers?
Cheers in advance.
You were on the right path, maybe you just missed something. Here is an example using POST:
HTML
<form action="page2.php" method="post">
<button type="submit" name="myButton" value="myValue1">Click Me!</button>
<button type="submit" name="myButton" value="myValue2">Click Me!</button>
...
</form>
PHP
$whichButton = $_POST['myButton'];
echo $whichButton; // myValue1 or myValue2
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, I made a thing where it gets the connection of a game server when you put it in a search box and press submit. Now, what I want it to do is to get the information when I type something like http://link.com/search.php?serverName=hello.com
and that hello.com would be the thing that it gets the information for.
You should consider looking into something called GET which can be added to your HTML form, which essentially adds the content entered into the 'searchbox' onto the URL at the top.
You can try it out using something like this..
<form action="search.php" method="GET">
<!-- Your form components here -->
<input type="submit" value="serverName">
See above that the value of the submit button needs to be set to what you want to appear at the end of the URL, in this case it would display '?serverName'
Then in regards to processing this data, you will need to look up searching algorithms in PHP, the best method is a FULL-TEXT search, but can be quite complicated to do, there are others that will get the job done.
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
Some more useful links:
http://www.w3schools.com/html/html_forms.asp
http://www.tutorialspoint.com/php/php_get_post.htm
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I basically want to create a simple text input with a button that says submit. And using PHP I want to be able to give a different answer based on what the users input was. For example, if the user inputs the number 6, I want it to display "You are on week 6" - Can someone help me? I am having some trouble putting this together to get it to work.
The simple version is something like this:
<?php
echo "You are on week".$_POST['week'];
Your form would look like:
<form method="post">
<input name="week" />
<input type="submit" value="Submit" />
</form>
But it's much more complicated than this; you have to validate the input and worry about injection attacks, among other things.
You will get better help on here if you provide some code that you already have in place and ask specific questions about particular problems.
When your form is
<form method="post">
<input name="nameOfYourInput"/>
<input type="submit" value="sendButton"/>
</form>
This doesn't depend on serverside language be it php or any other language.
Specific to php is only the printing of the variable in the input field.
which can be achieved by
<?php
echo "You are on week" . $_POST['nameOfYourInput'];
The $_POST is variable which is passed(automaticaly) to the server with the http request.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to figure out how to automatically get the search results from
http://pokemonshowdown.com/replay/
<form action="/replay/search/" method="get" data-target="replace">
<p style="text-align:center">
<label><input type="text" name="user" class="textbox" placeholder="Format or username" size="24" /></label>
<button type="submit"><strong>Search</strong></button>
</p>
</form>
but I don't know how to trigger the onsubmit action of the form using code, only by clicking on it X_X
I plan on getting the search results and using them to automatically cycle through replays so I don't have to keep clicking on them to watch.
If I got you right you want to initiate a search on an exterior site? Because it is a get-form it should be easily done by requesting the URL "http://pokemonshowdown.com/replay/search/?key=value". You do not have to really submit the form, just call the URL the form would call in case of an onclick-event.
Of course key and value have to be replaced by the field name and the value you want to insert. Multiple parameters would be concatenated, like key1=value1&key2=value2.