使用jquery / ajax 500内部服务器错误插入MYSQL DB

时间:2015-09-18 06:54:26

标签: php jquery html mysql ajax

我正在使用php / jquery和ajax将无线电检查的数据值插入到mysql数据库中,同时插入值我正在获取内部服务器500错误...

感谢任何帮助谢谢!

Html代码

<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代码

<?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);
?>

1 个答案:

答案 0 :(得分:1)

Mysql查询values($radio_div_clicked)";没有正确关闭,应该是

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

如果您正在使用Chrome,请点击网络标签,然后点击请求的链接。然后,再次单击预览或响应标题。通常会出现细节错误。