Member Avatar for anmol.raghuvanshi1
anmol.raghuvanshi1

Click Here

my problem of inserting data from radio-button has been resolved from above link but problems occurs when i increase the number of field from 5 to 18.

//here is my php code to process form 
//various fields in post methods are name attribute of radio buttons

<?php
    //Start session
    session_start();

    //Include database connection details
    require_once('connection/config.php');

    //Array to store validation errors
    //$errmsg_arr = array();

    //Validation error flag
    //$errflag = false;

    //Connect to mysql server
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        echo"Not Connected";
        die('Failed to connect to server: ' . mysql_error());
    }

    //Select database
    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
        echo "Not Selected";
        die("Unable to select database");
    }

    //Function to sanitize values received from the form. Prevents SQL injection
    function clean($str) {
        $str = @trim($str);
        if(get_magic_quotes_gpc()) {
            $str = stripslashes($str);
        }
        return mysql_real_escape_string($str);
    }

    //Sanitize the POST values
    $ans = clean($_POST['25rboption13']);



    //If there are input validations, redirect back to the same form
    /*if($errflag) {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        session_write_close();
        header("location: .php");
        exit();
    }
    */

    //Check whether the query was successful or not

        if(isset($_POST['submit'])){
        $ans1=isset($_POST['25rboption13']);
            $ans2=isset($_POST['129rboption13']);
                $ans3=isset($_POST['150rboption13']);
                    $ans4=isset($_POST['151rboption13']);
                        $ans5=isset($_POST['152rboption13']);
                        /*  $ans6=isset($_POST['153rboption13']);
                                $ans7=isset($_POST['154rboption13']);
                            $ans8=isset($_POST['592rboption13']);
                          $ans9=isset($_POST['593rboption13']);
                         $ans10=isset($_POST['594rboption13']);
                    $ans11=isset($_POST['595rboption13']);
                $ans12=isset($_POST['596rboption13']);
            $ans13=isset($_POST['1169rboption13']);
        */






        if($ans!=""){
        //Create query
        $qry="INSERT INTO diseases (q1,q2,q3,q4,q5) values(' ".$_POST['25rboption13']." ',' ".$_POST['129rboption13']." ',' ".$_POST['150rboption13']." ',' ".$_POST['151rboption13']." ',' ".$_POST['152rboption13']." ')";
        $result=mysql_query($qry);
        echo "data inserted";
    }       //Successful

        }else {
        die("Query failed");
    }
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Form Processing</title>
</head>

<body>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.