我有一个下拉列表,我可以通过ng_model指令(selectedName)访问所选名称,但我的问题是,当我尝试将所选选项值传递给数据库时,它传递一个空值,查询执行和文本框值正确传递的问题是使用下拉选项值..出了什么问题..在控制器中或使用php代码mysqli_real_escape_string部分。它很困惑..任何帮助
<select data-ng-model="selectedName" ng-options="item for item in names">
</select>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = ["7G", "8G", "13G", "15G", "23G","26G"];
app.controller("usercontroller", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'selectedName':$scope.selectedName,
'selectedProject':$scope.selectedProject, 'user':$scope.user}
).success(function(data){
alert(data);
});
}
$connect = mysqli_connect("localhost","root","","microlinks");
$data = json_decode(file_get_contents("php://input"));
if(count($data) > 0){
$frequency = mysqli_real_escape_string($connect, $data->selectedName);
$project = mysqli_real_escape_string($connect, $data->selectedProject);
$user = mysqli_real_escape_string($connect, $data->user);
$query = "insert into links(frequency,project,user,date) values ('$frequency','$project', '$user',)";
if(mysqli_query($connect, $query))
{
echo "Hello World";
}
else
{
echo 'Error';
}
}