<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[I want to Enter my radio button value to the database in php]]></title><description><![CDATA[<p dir="auto">I have tried t enter my radio button value to the database and in the console showing an error.<br />
I looked everywhere and tried everything to get the selected value from a group of radio buttons and i failed.<br />
Can anyone help me out.<br />
here is my code</p>
<p dir="auto"><strong>admin-map.php</strong></p>
<pre><code>&lt;?php
include_once 'header.php';
include_once 'locations_model.php';
?&gt;


&lt;div id="map"&gt;&lt;/div&gt;

&lt;!------ Include the above in your HEAD tag ----------&gt;
&lt;script&gt;
    var map;
    var marker;
    var infowindow;
    var red_icon =  'http://maps.google.com/mapfiles/ms/icons/red-dot.png' ;
    var purple_icon =  'http://maps.google.com/mapfiles/ms/icons/purple-dot.png' ;
    var locations = &lt;?php get_all_locations() ?&gt;;

    function initMap() {
        var france = {lat: 6.8602, lng: 80.0535};
        infowindow = new google.maps.InfoWindow();
        map = new google.maps.Map(document.getElementById('map'), {
            center: france,
            zoom: 7
        });


        var i ; var confirmed = 0;
        for (i = 0; i &lt; locations.length; i++) {

            marker = new google.maps.Marker({
                position: new google.maps.LatLng(locations[i][1], locations[i][2]),
                map: map,
                icon :   locations[i][5] === '1' ?  red_icon  : purple_icon,
                html: document.getElementById('form')
            });

            google.maps.event.addListener(marker, 'click', (function(marker, i) {
                return function() {
                    confirmed =  locations[i][5] === '1' ?  'checked'  :  0;
                    $("#confirmed").prop(confirmed,locations[i][5]);
                    $("#id").val(locations[i][0]);
                    $("#description").val(locations[i][3]);
                    $("#image").attr("src", locations[i][4]);;
                    $("#form").show();
                    infowindow.setContent(marker.html);
                    infowindow.open(map, marker);
                }
            })(marker, i));
        }
    }

    function saveData() {
        var confirmed = document.getElementById('confirmed').checked ? 1 : 0;
        var id = document.getElementById('id').value;
        var Condition=document.getElementById('Condition').value;

        var fd = new FormData();

        fd.append('confirmed', confirmed);
        fd.append('id', id);
        // fd.append('Condition',Condition);

        $.ajax({
            url : 'confirm_location.php',
            type : 'POST',
            data : fd,
            processData: false,
            contentType: false,
            async: false,
            success : function(data) {              
                alert(data);

                if(data == "Location added.")
                {
                    infowindow.close();
                    window.location.reload(true);
                    return;
                }

                infowindow.setContent("&lt;div style='color: purple; font-size: 25px;'&gt;Inserting Errors&lt;/div&gt;");
                
            },
            error : function(request,error)
            {
                alert(error);
            }
        });
    }


    function downloadUrl(url, callback) {
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;

        request.onreadystatechange = function() {
            if (request.readyState == 1) {
                callback(request.responseText, request.status);
            }
        };

        request.open('GET', url, true);
        request.send(null);
    }


&lt;/script&gt;

&lt;div style="display: none" id="form"&gt;
    &lt;table class="map1"&gt;
        &lt;tr&gt;
            &lt;image id="image" src="" style="width: 250px; height: auto;"&gt;
            &lt;input name="id" type='hidden' id='id'/&gt;
            &lt;td&gt;&lt;a&gt;Description:&lt;/a&gt;&lt;/td&gt;
            &lt;td&gt;&lt;textarea disabled id='description' placeholder='Description'&gt;&lt;/textarea&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;b&gt;Confirm Location ?:&lt;/b&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input id='confirmed' type='checkbox' name='confirmed'&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;b&gt;Set Condition&lt;/b&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="radio" name="Condition" value="1" &gt;Normal&lt;/td&gt;
            &lt;td&gt;&lt;input type="radio" name="Condition" value="2" &gt;Bad &lt;/td&gt;
            &lt;td&gt;&lt;input type="radio" name="Condition" value="3"&gt;Very Bad&lt;/td&gt;&lt;input&gt;
        &lt;/tr&gt;

        &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type='button' value='Save' name="submit_btn" onclick='saveData()'/&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
&lt;/div&gt;
&lt;script async defer
        src="https://maps.googleapis.com/maps/api/js?language=en&amp;key=AIzaSyA-AB-9XZd-iQby-bNLYPFyb0pR2Qw3orw&amp;callback=initMap"&gt;
&lt;/script&gt;


</code></pre>
<p dir="auto"><strong>confirm_location.php</strong></p>
<pre><code>&lt;?php

if(isset($_POST['confirmed']) &amp;&amp; isset($_POST['id']))
{
	$con=mysqli_connect ("localhost", 'root', '','demo');

	if (!$con) {
	    die('Not connected : ' . mysqli_connect_error());
	}

	$id = mysqli_real_escape_string($con, $_POST['id']);
	$confirmed = mysqli_real_escape_string($con, $_POST['confirmed']);
	$Condition = mysqli_real_escape_string($con,$_POST['Condition']);

	// update location with confirm if admin confirm.
	$query = "update locations set location_status = $confirmed WHERE id = $id ";
	$query_condition="UPDATE locations set locationCondition = $Condition where id=$id";

	$result = mysqli_query($con,$query);
	// $result2=mysqli_query($con,$query_condition);

	if ($result) {
	    echo 'Location added.';
	    return;
	}

	echo 'Can\'t add location';
}
else
{
	echo 'Please enter required fields';
}

</code></pre>
]]></description><link>https://lankadevelopers.lk/topic/41/i-want-to-enter-my-radio-button-value-to-the-database-in-php</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 16:43:24 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/41.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 20 Dec 2018 06:40:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 14:16:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/34">@akashmanujaya</a>  i have done small change to code, try this</p>
<pre><code>function saveData() {
        var confirmed = document.getElementById('confirmed').checked ? 1 : 0;
        var id = document.getElementById('id').value;
        var Condition=$('input[name="Condition"]:checked').val(); //check this line
 
        var fd = new FormData();
 
        fd.append('confirmed', confirmed);
        fd.append('id', id);
        fd.append('Condition',Condition); //uncomment this line
}
</code></pre>
]]></description><link>https://lankadevelopers.lk/post/271</link><guid isPermaLink="true">https://lankadevelopers.lk/post/271</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 20 Dec 2018 14:16:58 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 14:12:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/34">@akashmanujaya</a> i'll check</p>
]]></description><link>https://lankadevelopers.lk/post/270</link><guid isPermaLink="true">https://lankadevelopers.lk/post/270</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 20 Dec 2018 14:12:52 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 14:12:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/34">@akashmanujaya</a> i'll check</p>
]]></description><link>https://lankadevelopers.lk/post/269</link><guid isPermaLink="true">https://lankadevelopers.lk/post/269</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 20 Dec 2018 14:12:52 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 14:10:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a>  I found the error. its working perfecly.. thanks for your help</p>
]]></description><link>https://lankadevelopers.lk/post/268</link><guid isPermaLink="true">https://lankadevelopers.lk/post/268</guid><dc:creator><![CDATA[akashmanujaya]]></dc:creator><pubDate>Thu, 20 Dec 2018 14:10:34 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 14:06:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a> Your code is not working. i already set the column for default value as 1. but i check third radio button which value is 3, it still input 1 as the value. Why is that?  please help me out</p>
]]></description><link>https://lankadevelopers.lk/post/267</link><guid isPermaLink="true">https://lankadevelopers.lk/post/267</guid><dc:creator><![CDATA[akashmanujaya]]></dc:creator><pubDate>Thu, 20 Dec 2018 14:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 10:34:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/34">@akashmanujaya</a> ur welcome :smiley:</p>
]]></description><link>https://lankadevelopers.lk/post/253</link><guid isPermaLink="true">https://lankadevelopers.lk/post/253</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 20 Dec 2018 10:34:28 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 10:15:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a>  Thankx  A lot</p>
]]></description><link>https://lankadevelopers.lk/post/251</link><guid isPermaLink="true">https://lankadevelopers.lk/post/251</guid><dc:creator><![CDATA[akashmanujaya]]></dc:creator><pubDate>Thu, 20 Dec 2018 10:15:05 GMT</pubDate></item><item><title><![CDATA[Reply to I want to Enter my radio button value to the database in php on Thu, 20 Dec 2018 07:17:03 GMT]]></title><description><![CDATA[<p dir="auto">in your <code>saveData()</code> method</p>
<pre><code>function saveData() {
        var confirmed = document.getElementById('confirmed').checked ? 1 : 0;
        var id = document.getElementById('id').value;
        var Condition=$('input[name= Condition]:checked').val(); //get the radio button value like this, it's easy to use jquery than javascript

        var fd = new FormData();

        fd.append('confirmed', confirmed);
        fd.append('id', id);
        fd.append('Condition',Condition); //uncomment this line
}
</code></pre>
]]></description><link>https://lankadevelopers.lk/post/247</link><guid isPermaLink="true">https://lankadevelopers.lk/post/247</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 20 Dec 2018 07:17:03 GMT</pubDate></item></channel></rss>