比较来自世界各地的卖家的域名和 IT 服务价格

添加输入数据 bootstrap 在 mysql, 使用 ajax, jquery 和 php

在这里我有一个模态窗口 bootstrap:


 Modal 
<div aria-hidden="true" aria-labelledby="myModalLabel" class="modal fade" id="myModal" role="dialog" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
<h4 class="modal-title" id="myModalLabel">Add new row</h4>
</div>
<div class="modal-body">
......
<div class="input-group">
<span class="input-group-addon">Ime</span>
<input class="form-control" id="Ime" placeholder="Upisi ime" type="text"/>
</div>

<div class="input-group">
<span class="input-group-addon">Pol</span>
<input class="form-control" id="pol" placeholder="Pol /male/female/" type="text"/>
</div>

<div class="input-group">
<span class="input-group-addon">Godine</span>
<input class="form-control" id="godine" placeholder="Godine starosti" type="text"/>
</div>

<div class="input-group">
<span class="input-group-addon">Broj pojedenih krofni</span>
<input class="form-control" id="krofne" placeholder="Pojedene krofne" type="text"/>
</div>

</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
<button class="btn btn-primary" id="newData" type="button">Add new data</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div> /.modal


我想要 ADD 这些数据来自数据库中的输入字段 mysql 用专栏:名称,性别,年龄吃甜甜圈

所以我写了代码 ajax jquery:


<script>
//add data to database using jquery ajax
$/"#newData"/.click/function// {
//in here we can do the ajax after validating the field isn't empty.
if/$/"#message-content"/.val//!=""/ {
$.ajax/{
url: "messages.php",
type: "POST",
async: true,
data: { Name:$/"#ime"/.val//, Gender:$/"#pol"/.val//, Age:$/"#godine"/.val//, Donuts_eaten:$/"#krofne"/.val//}, //your form data to post goes here as a json object
dataType: "html",

success: function/data/ {
$/'#output'/.html/data/;
},
}/;
} else {
//notify the user they need to enter data
}
}/;
</script>


现在我试图写一个文件 php, 但我开始这个节目,我只知道如何连接,所以我写道:


php

$con = mysql_connect/'localhost', 'gmaestro_agro', 'password'/ or die/'Error connecting to server'/;

mysql_select_db/'gmaestro_agro', $con/;

//WHAT I NEED TO WRITE HERE TO ADD DATA TO MYSQL

?


我有这一切的演示:
http://agrotime.roadvoyage.com/index1.html
, 因此,单击“添加新”按钮以获取模态窗口...

请帮帮我。

对不起,我的英语很糟糕,但我孜孜不倦地学习
已邀请:

裸奔

赞同来自:

就像你必须写的那样简单:


$con = mysql_connect/.../;
if/$con != false/ {
mysql_select_db/'gmaestro_agro', $con/;
$query = "INSERT INTO `table` /`name`, `gender`, `age`, `donuts_eaten`/ VALUES /";
$query .= mysql_real_escape_string/$_POST['Name']/ . ", ";
$query .= mysql_real_escape_string/$_POST['Gender']/ . ", ";
$query .= mysql_real_escape_string/$_POST['Age']/ . ", ";
$query .= mysql_real_escape_string/$_POST['Donuts_eaten']/;
$query .= "/";
$result = mysql_query/$query/;
if/$result != false/ {
echo "success!";
} else {
echo "an error occured saving your data!";
}
}


我想顺便问一下,你知道你的名字是什么 'table' 你的呢 'columns' 在你的 mysql DB,可以自己修复它们。 您请求中的所有数据 AJAX 显示在数组中 PHP POST.

要回复问题请先登录注册