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

  • Home
  • SEARCH
  • 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 8523523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:25:59+00:00 2026-06-11T07:25:59+00:00

Suppose that I have the code php as below: <?php include(connectdb.php); $check1 = ;

  • 0

Suppose that I have the code php as below:

<?php
    include("connectdb.php");
    $check1 = "";
    $check2 = "";
    $check3 = "";
    $check4 = "";
    $check5 = "";
    $query = "SELECT * FROM tblworkfaire";
    $res = mysql_query($query) or die(mysql_error());
        if($res){
            while($data = mysql_fetch_array($res)){
                if($data['1.DesTechnique'] == 1){
                    $check1 = "CHECKED";    
                    echo $check1;
                }
                else if($data['1.DesTechnique'] == 2){
                    $check2 = " CHECKED";   
                }
                else if($data['1.DesTechnique'] == 3){
                    $check3 = "CHECKED";    
                }
                else if($data['1.DesTechnique'] == 4){
                    $check4 = "CHECKED";    
                }
                else if($data['1.DesTechnique'] == 5){
                    $check5 = "CHECKED";    
                }
            }
        }
        else{
            echo "Fail";
        }

?>

And Html code:

 <form  action="word2html.php" method="post">
    <input type="radio" name="number1" value="1" checked="<? $check1; ?>">
            </b><b>
            <input name="number1" type="radio" value="2" checked="<? $check2; ?>">
            </b><b>
            <input name="number1" type="radio" value="3" checked="<? $check3; ?>">
            </b><b>
            <input  name="number1" type="radio" value="4" checked="<? $check4; ?>">
            </b><b>
            <input name="number1" type="radio" value="5" checked="<? $check5; ?>">
            </b>

What I need:

I have stored the radio box value in database,if I select value from database equal 1,it will check the radio box that have the value equal 1.

Problem:

I can only select value of radio box from database and it dose not work.How do I fix this? Anyone help me please, Thanks.

  • 1 1 Answer
  • 0 Views
  • 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-06-11T07:26:00+00:00Added an answer on June 11, 2026 at 7:26 am

    That’s some rather horrible code.

    First problem: You’re doing a while() loop to fetch results from your query. If you’re fetching multiple rows of data, the you’ll be setting all or some of those $checkX variables, yet not actually doing anyhing with them during that particular loop iteration. Assuming you fetch enough rows, eventually ALL of those variables will be checked and you end up selecting all of your radio buttons.

    If you’re expecting only a single row of data, then the while() is simply cargo cult programming.

    Second problem. You’ve repeated a lot of code in there, and define a lot of variables, for something that could be done far easier/cleaner with a loop. e.g.

    for ($i = 1; $i <= 5; $i++) {
       $checked = ($data['1.DesTechnique'] == $i) ? ' checked="checked"' : '';
       echo <<<EOL
    <input name="number1" type="radio" value="$i"$checked>$i<br />
    
    EOL;
    }
    

    No $checkX variables, no repeated inputs. just a nice loop doing the output for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php code below where it is suppose to display my buttons,
I have the php webservice code below, what I am suppose to do, so
I have the PHP code below. It is supposed to select up to ten
Suppose that I have a string $var : //php code $var = hello,world,test; $exp
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
Suppose I have code that maintains a parent/children structure. In such a structure I
I have this code that suppose to place the marker by the latlng public
Suppose I have a line of code that starts like the following: Func1(Func2(Func3 Is
Suppose we have the xhr 'POST' request that returns 'redirect' status code. In that
I have this javascript that i want to run in php, the code bellow

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.