0

I'm inserting radio checked data values into mysql db with php/jquery and ajax while inserting values i'm getting internal server 500 error...

Any help is appreciated Thanks!

Html Code

<div>
    <input class="radio_div_clicked" value="<?php echo $row['name'];?> name="radio_section" id="<?php echo $row['id'];?>"/>
    <p><?php echo $row['name'];?></p>
    <button id="add_feed">Add</button>
</div>

JQUERY CODE

<script type="text/javascript">
$('body').delegate('#add_feed','click',function(){

    var radio_div_clicked = $('input:radio[name=radio_section]:checked').val();
    $.ajax({
            type:"POST",
            url:"index.php",
            cache: false,
            data:{
                insert_section:1,
                radio_div_clicked:radio_div_clicked
            },
            success:function(data)
            {
                alert('Successfully Inserted Into Table');
            }
        });
    }

});
</script>

PHP code

<?php 
    $con = @mysql_connect('localhost','root','') or die('failed to connect server');
    $db = mysql_select_db('demo',$con) or die('failed to select db');
    if(isset($_POST['insert_section']))
    {
        $radio_div_clicked = mysql_real_escape_string($_POST['radio_div_clicked']);
        $sql = mysql_query("insert into test(name) values($radio_div_clicked)";
        if($sql)
        {
            echo "Successfully Inserted Into Table";
        }
        else
        {
            echo "Failed To Insert Value Into Table"
        }
    }
?>
<?php 
    mysql_close ($con);
?>
2
  • What error do you get? Commented Sep 18, 2015 at 6:58
  • @DevAlien 500 Internal Server Error Thanks! Commented Sep 18, 2015 at 7:00

1 Answer 1

1

Mysql query values($radio_div_clicked)"; did't closed properly, should be

$sql = mysql_query("insert into test(name) values('".$radio_div_clicked."')");

If you're using chrome, click on network tab, and click the requested link. Then, again click on preview or response header. Usually the details errors showing up there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.