Problem with form selection

When i select an option in one form it shud display the value like how many times its selected.for ex if i select cricket the next form shud display the value 1 infront of cricket if it is selected once

Comments<select name="Comments">
<option value="tennis">tennis</option>
<option value="basketball">basketball</option>
<option value="football">football</option>
<option value="cricket">cricket</option>

</select>

Post the code you have got so far, and I’m sure someone will have a look to see why it isn’t doing what you need. If we can see the code, it might make the question clearer.

Welcome, @bhavanashetty06. There is no question here. What is it that you would like to discuss or ask about?

By the way, you will probably get more people reading your thread if you make the title very short and explaining the topic, and put that long title as part of the post.

If you have questions about your code, it would help if you could post your code here for us to see. Just paste it in, highlight it, and choose the </> icon from the list above. Or you could place three backticks (`) on the line before and three backticks on the line after the pasted code.

By the way, if you are hoping to have people do the coding to solve your problem for you, you might be disappointed because they probably won’t do it. But if you show what you have so far, they will be very happy to help out.

Sounds like you might be wanting JS rather than PHP, but as said, more info is needed.

Comments<select name="Comments">
<option value="tennis">tennis</option>
<option value="basketball">basketball</option>
<option value="football">football</option>
<option value="cricket">cricket</option>

</select>

``` form2.php

tenis:<input type=“text” name= " “?php echo $_POST[”“]; ? >
basketball:<input type=“text” name= " " ?php echo $_POST[”“]; ? >
football:<input type=“text” name= " “?php echo $_POST[””]; ? >
cricket:<input type=“text” name= " " ?php echo $_POST[“”]; ? >

THANK YOU for the responding means a lot.I have posted another question with the similar problem.Hope I get a solution this time.

How much experience do you have coding in PHP? This will determine the type of help you get here.

Right now, the code you gave us is just a few pieces. Do you have the code for the entire form so that we can see where you are sending the form for processing? eg the action attribute in <form action = " " method = "post">.

And is form2.php in a separate file, or are you trying to put everything all in the same file like it looks here?

What are you planning on putting inside the name attribute and the $_POST[""] for each item?

<html>
<head></head>
<body>
 welcome to the page<br/>

<form action="connect.php" method="post">
<?php 
$date = date(" Y-m-d"); 
echo "$date";
?>
Username:<input type="text" name="Username">
Action:<select name="Action">
<option value="Suspended">Suspended</option>
<option value="Disabled">Disabled</option>
<option value="Password Reset">Password Reset</option>
 </select>


 Comments<select name="Comments">
<option value="performance">performance</option>
<option value="malware">malware</option>
<option value="spamming">spamming</option>
<option value="mysql abuser">mysql abuser</option>
<option value="backup/storage">backup/storage</option>
</select>

Adminname<select name="Adminname">
<option value="RIA">RIA</option>
<option value="SIA">SIA</option>
<option value="TIA">TIA</option>

</select>


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


</form>
</body>
</html>


2nd form```
<?php $thedate = date("d F Y"); echo "$thedate"; ?>

date:
Malware:<input type=“text” name= " “?php echo $_POST[”“]; ? >
Spamming:<input type=“text” name= " " ?php echo $_POST[”“]; ? >
Performance:<input type=“text” name= " “?php echo $_POST[””]; ? >
MySQL Abuser:<input type=“text” name= " " ?php echo $_POST[“”]; ? >
Backup/Storage:<input type=“text” name= " “?php echo $_POST[”"]; ? >
Count:

``` HERE connect.php has the mysql connection code.Now my problem is when I select an option from the dropdown list it should be stored as a number in 2nd form i.e if i select malware in 1st form in the 2nd form it should display as malware:1.if i select it once again it shud display malware:2..similarly for all the options

form2.php is in separate file.
I have posted another question with complete details.just few minutes back.

There’s no code in the second form to actually display the results of the POST variables - you need to add the POST field names. Although I’m still not that clear on exactly what you’re trying to do.

Malware:<input type=“text” name= " "?php echo $_POST[“Malware”]; ? >
but this will not display the number

If I read it properly, I think he wants to do the following.

  1. Submit Form
  2. Show result of what was “checked”
  3. Go back to Form
  4. Submit Form again
  5. Show what was checked from the first visit and what was checked “just now”, if they were the same, show as “item: 2”

In which case, the easiest approach is to use Session to store the checked item as a key in an array and the counter (number of times it was “checked”) as the value, incrementing it on each time it is submitted via the form.

There are some assumptions with that approach though, 1) you don’t need it to span multiple users, you just want to track how often a single person is choosing each option, 2) You don’t need to maintain the information long term, you only need it for the length of time the user is visiting your page.

Thank You.Your almost there but this not exactly what I want.[quote=“cpradio, post:12, topic:251335, full:true”]
If I read it properly, I think he wants to do the following.

  1. Submit Form
  2. Show result of what was “checked”
  3. Go back to Form
  4. Submit Form again
  5. Show what was checked from the first visit and what was checked “just now”, if they were the same, show as “item: 2”

In which case, the easiest approach is to use Session to store the checked item as a key in an array and the counter (number of times it was “checked”) as the value, incrementing it on each time it is submitted via the form.

There are some assumptions with that approach though, 1) you don’t need it to span multiple users, you just want to track how often a single person is choosing each option, 2) You don’t need to maintain the information long term, you only need it for the length of time the user is visiting your page.
[/quote]

Then you need to define what it is you do want. From what I understood, you want the user to select an option, then show how often that selection was choosen, right?

As that is what I described, but again the solution I suggested using $_SESSION makes 2 assumptions, and if neither of those assumptions are right, then you need to use a different solution other than $_SESSION (such as, storing the data in a flat file, or a database and retrieving the number of times something was choosen from said storage).

YES.This time you have hit the bull’s eye.

Can U please explain in code like how would it work with an example code similar to my requirement…It would be very helpful.

Right now I am clueless…

But I Have been specifically told to use html,php and mysql.

As best as I can figure, the steps would be like

  • form page is requested
  • indentify user
  • check if user has previously submmitted the form
  • collect previuos data if it exists
  • output the form displaying any previous data

Because select options are inside the <select> I’m having trouble thinking of where the “times before” stuff would be shown. Personally I think I would simply insert a paragraph something like “you selected ___ ## times before”

But maybe you want something like

Comments<select name="Comments">
<option value="tennis">tennis <?php echo $previous_tennis_count; ?></option>
<option value="basketball">basketball <?php echo $previous_basketball_count; ?></option>
<option value="football">football <?php echo $previous_football_count; ?></option>
<option value="cricket">cricket <?php echo $previous_cricket_count; ?></option>
</select>

This is the part I’m still confused about.

@bhavanashetty06, are you supposed to only tally the choices per user, or all users?

Example:
Let’s say your three choices are Blue, Yellow and Green

User A visits the form and selects Yellow, and sees
Blue: 0
Yellow: 1
Green: 0

User B visits the form and selects Green.

Do they see
Blue: 0
Yellow: 0
Green: 1

Or do they see (since User A already choose Yellow)
Blue: 0
Yellow: 1
Green: 1

Based on the answer to that question, we can guide you, but we won’t do the work for you.

2 Likes