gpt4 book ai didi

php - AngularJS、PHP 和 Mysqli

转载 作者:行者123 更新时间:2023-11-29 21:04:18 25 4
gpt4 key购买 nike

我正在尝试填写表单,然后通过 Angular Controller 将数据传递到 php 文件......似乎不起作用。有时,当我更多时,我会在 Mysqli 中输入空白条目,但我似乎无法使其工作。

我知道这与我无法弄清楚的表单有关,如果我放入一个更简单的文本框示例,它就可以工作。

<!DOCTYPE html>
<html>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="final.css">
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript">function init() {calendar.set("date");}</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link href='http://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css' rel='stylesheet' type='text/css'>
<body>
<header>
<div class="row">
<img src="Final.png" alt="company logo">
</div>
</div>
<div class="top-bar" id="main-menu">
<ul class="menu vertical medium-horizontal expanded medium-text-center">
<li><a href="Home.php">Login</a></li>
<li><a href="Dad.php">Dad</a></li>
<li><a href="Mom.php">Mom</a></li>
<li><a href="Son.php">Son</a></li>
<li><a href="Daughter.php">Daughter</a></li>
</ul>
</div>
header>
<body onload="init()">
<div align="center" ng-app="myapp" ng-controller="studentcontroller">
<form id ="" action="" method="post" >
<h2>Enter New Chore</h2>
<table>
<tr>
<td>Name :</td> <td>
<select name="user" style="Color: Black" required ng-model="DName">
<option disabled="disabled" selected="selected">Select Person.</option>
<option value="Mom">Mom</option>
<option value="Dad">Dad</option>
<option value="Son">Son</option>
<option value="Daughter">Daughter</option>
</select>
</tr>
<tr>
<td>Chore Title :</td><td><input type = "text" name = "choretitle" class = "box" style="width: 300px;"required ng-model="DTitle"></td><br>
</tr>
<tr>
<td>Due Date :</td><td><input type="text" name="date" id="date"style="width: 300px;"required ng-model="DDate"></td><br>
</tr>
<tr>
<td>Chore Description :</td><td><textarea name="desc" rows="4" cols="50" maxlength="256" style="width: 300px;" ng-model="DDesc"></textarea><br>
</tr>
<tr>
<td><button type="submit" name="btn-add" ng-click="insertdata()">Add Chore</button></td>
</tr>
</table>
</form>
</div>

<script>
var app = angular.module("myapp",[]);
app.controller("studentcontroller",function($scope,$http){
$scope.insertdata = function() {
$http.post("insert.php",{'DName':$scope.DName,'DTitle':$scope.DTitle,'DDate':$scope.DDate,'DDesc':$scope.DDesc})
.success(function(data,status,headers,config){
console.log("Inserted Successfully!");
});
}
});
</script>

</body>
<footer id="footer">
<div class="row expanded">
<div class="medium-8 columns">
<ul class="menu">
<li><a href="#">Legal</a></li>
<li><a href="#">Partner</a></li>
<li><a href="#">Explore</a></li>
</ul>
</div>
<div class="medium-6 columns">
<ul class="menu align-right">
</ul>
</div>
</div>
</footer>

////PHP
<?php
$data = json_decode(file_get_contents("php://input"));
$assingedTo = $data->DName;
$choreName = $data->DTitle;
$choreDesc = $data->DDesc;
$dueDate = $data->DDate;
$status = "Open";
$DBConnect = mysqli_connect("localhost", "root", "qwerty", "chores");
$sql = "insert statement"
$result = mysqli_query($DBConnect, $sql);
?>

最佳答案

这就是我在使用 Angular PHP 时编码表单的方式。尝试将数据作为一个 Javascript 对象提取到 Controller 中。

<form ng-submit="submitChores(chores)" >
<h2>Enter New Chore</h2>
<table>
<tr>
<td>Name :</td> <td>
<select name="user" style="Color: Black" required ng-model="chores.DName">
<option disabled="disabled" selected="selected">Select Person.</option>
<option value="Mom">Mom</option>
<option value="Dad">Dad</option>
<option value="Son">Son</option>
<option value="Daughter">Daughter</option>
</select>
</tr>
<tr>
<td>Chore Title :</td><td><input type = "text" name = "choretitle" class = "box" style="width: 300px;"required ng-model="chores.DTitle"></td><br>
</tr>
<tr>
<td>Due Date :</td><td><input type="text" name="date" id="date"style="width: 300px;"required ng-model="chores.DDate"></td><br>
</tr>
<tr>
<td>Chore Description :</td><td><textarea name="desc" rows="4" cols="50" maxlength="256" style="width: 300px;" ng-model="chores.DDesc"></textarea><br>
</tr>
<tr>
<td><button type="submit" name="btn-add">Add Chore</button></td>
</tr>
</table>
</form>

Controller

app.controller("studentcontroller",function($scope,$http){
$scope.submitChores = function(data){
var $data = angular.toJson(data);
$http.post("insert.php",$data)
.success(function(data,status,headers,config){
console.log("Inserted Successfully!");
});
}

});

这就是表单对我的工作方式,并且从来没有出现过无法获取 PHP 文件中的数据的情况。快乐编码

关于php - AngularJS、PHP 和 Mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36957531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com