Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:08:37+00:00 2026-05-24T12:08:37+00:00

I am trying to create a math question set for a website where the

  • 0

I am trying to create a math question set for a website where the user will be given an equation and they have to write the answer in the form.

My HTML mark up looks like this

    <p> Please write the sum of these two numbers </p>
    <label for="num1">Number1: <?php echo rand(2,200)?> 
    <label for="num2">Number2: <?php echo rand(2,200)?> 
    <input name="sum" type="text" />

I want to be able to check if the entered the right sum of the two values that are generated. This is just generic at the point. It will eventually end up having more variables and different math operators for the question

How do I do the following with PHP server side script:

a) The value that the Label’s have from echo rand() function and
b) how do I get the code to store them as variables and output to the screen?

PS: I have to do it on php side and I am aware this might be do-able with Javascript/Jquery.

Thank you in advance for your help.

Varun

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:08:37+00:00Added an answer on May 24, 2026 at 12:08 pm

    Javascript aside, you can’t access anything to do with the <label>, the easiest way (aside from using session data) is to use an <input>.

    You’ll want to declare the value once, so you don’t get a different value displayed to the user than what is stored in the input. Quick example:

    <?php
    $num1 = rand(2,200);
    $num2 = rand(2,200);
    ?>
    
    <p> Please write the sum of these two numbers </p>
    <label for="num1">
        Number1: <?php echo $num1; ?>
        <input name="num1" type="hidden" value="<?php echo $num1; ?>" />
    </label>
    <label for="num2">
        Number2: <?php echo $num2; ?>
        <input name="num2" type="hidden" value="<?php echo $num2; ?>" />
    </label>
    <input name="sum" type="text" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a math quiz and I only want the user to
This is more like a math related question. I'm trying to create a cute
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
Trying to create a user account in a test. But getting a Object reference
I've started to create a website where it's users are effectively tracked (they know
I'm trying to create a search form (rails 3.1) where one of the search
I am basically trying to create a display object transformation manager which will allow
I am trying to create a function that will change the color of a
I'm setting up a little math study site and am trying to create an
Hello I’m a trying to create a feature where an user an add an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.