Javascript 在Chrome和safari中加载两次PHP文件
当我尝试用php文件插入mydata时,我遇到了一个问题,然后我在网络选项卡上检查,它显示我的insertt.php运行了2次,然后它将空行插入到我的数据库中,我不想在这里看到我的代码 index.phpJavascript 在Chrome和safari中加载两次PHP文件,javascript,php,mysql,angularjs,post,Javascript,Php,Mysql,Angularjs,Post,当我尝试用php文件插入mydata时,我遇到了一个问题,然后我在网络选项卡上检查,它显示我的insertt.php运行了2次,然后它将空行插入到我的数据库中,我不想在这里看到我的代码 index.php <!DOCTYPE html> <html lang="en" ng-app="myApp" > <head> <link rel="icon" type="image/png" href="icon128-2x.p
<!DOCTYPE html>
<html lang="en" ng-app="myApp" >
<head>
<link rel="icon"
type="image/png"
href="icon128-2x.png">
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">-->
<title>My AngularJS App</title>
<!--<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css">-->
<link rel="stylesheet" href="app.css">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<script src="bower_components/html5-boilerplate/dist/js/vendor/modernizr-2.8.3.min.js"></script>
<style>
input {
text-align: center;
}
</style>
</head>
<body style="background-color:lightgreen;">
<!--div class="jumbotron" style="background-color:lightblue;">
<h1>Bootstrap Tutorial</h1>
<p>Bootstrap is the most popular HTML, CSS, and JS framework for developing responsive, mobile-first projects on the web.</p>
</div-->
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Thaishop Online</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#!/view1">หน้าหลัก <span class="sr-only">(current)</span></a></li>
<li><a href="#!/view2">วิธีการใช้งาน</a></li>
<!-- <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>-->
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#!/view2">สมัครสมาชิก</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#!/viewLogin">เข้าสู่ระบบ</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<img src="img\banner.jpg" class="img-responsive" alt="Cinque Terre"style="width: 100%; height: 350px;" >
<div ng-view></div>
<script src="js/jquery-2.2.3.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="app.js"></script>
<script src="view1/view1.js"></script>
<script src="view2/view2.js"></script>
<script src="viewLogin/viewLogin.js"></script>
<script src="viewSaveCafeDetail/viewSaveCafeDetail.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
</body>
</html>
view2.html
<div >
<form name="form1" method="post" style="text-align:center;" align="center">
<div class="form-group col-md-6 col-xs-12 col-md-offset-3" >
<label for="InputName" ><h1>กรอกข้อมูลผู้ใช้</h1></label>
<input type="text" class="form-control" ng-model="formdata.Firstname" name="inputFirstname" placeholder="ชื่อจริง" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Lastname" name="inputLastname" placeholder="นามสกุล" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Username" placeholder="Username" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="password" class="form-control" ng-model="formdata.Password" placeholder="Password" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="password" class="form-control" ng-model="formdata.ConfirmPassword" placeholder="Password อีกครั้ง" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Email" name="inputEmail" placeholder="E-Mail" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Tel" name="inputTel" placeholder="โทรศัพท์">
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.CafeName" name="inputCafeName" placeholder="ชื่อร้าน">
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="hidden" ng-model="table" value="cafe">
<input type="hidden" ng-model="ajouter" value="1" >
<input ng-model="insertuser" ng-show="formdata.Firstname.length && formdata.Lastname.length && formdata.Username.length && formdata.Password.length &&
formdata.ConfirmPassword.length && formdata.Email.length && formdata.Tel.length && formdata.CafeName.length" ng-click="SignUp();" type="submit" value="insert" class="btn btn-primary">
<!--<input ng-model="insertuser" ng-click="SignUp();" type="submit" value="insertt" class="btn btn-primary">-->
</div>
</form>
<!--<input type="text" ng-model="cafe_id" value="" placeholder="CafeId"></br>
<input type="text" ng-model="CafeName" value="" placeholder="CafeName"></br>
<input type="text" ng-model="Username" value="" placeholder="Username"></br>
<input type="text" ng-model="CafeUrl" value="" placeholder="CafeUrl"></br>
<input type="hidden" ng-model="table" value="cafe">
<input type="hidden" ng-model="ajouter" value="1" >
<input ng-hide="update" ng-click="SignUp();" type="submit" value="insert" class="btn btn-primary">
<input ng-show="update" ng-click="update();" type="submit" value="update" class="btn btn-primary">
<input ng-click="getData();" type="submit" value="get" class="btn btn-primary">-->
<table border="1">
<tr ng-repeat="x in content">
<td>{{x.id}}</td>
<td>{{x.CafeName}}</td>
<td><button ng-click="editData(x.id)" >Edit</button></td>
<td><button ng-click="deleteData(x.id)" >Del</button></td>
</tr>
</table>
</form>
</div>
警告:当使用mysqli
时,您应该使用和将用户数据添加到查询中。不要使用字符串插值或串联来完成此操作,因为您已经创建了严重的错误。切勿将$\u POST
或$\u GET
数据直接放入查询中,如果有人试图利用您的错误,这可能非常有害。警告:使用mysqli
时,您应该使用并将用户数据添加到查询中。不要使用字符串插值或串联来完成此操作,因为您已经创建了严重的错误。切勿将$\u POST
或$\u GET
数据直接放入查询,如果有人试图利用您的错误,这可能非常有害。
<div >
<form name="form1" method="post" style="text-align:center;" align="center">
<div class="form-group col-md-6 col-xs-12 col-md-offset-3" >
<label for="InputName" ><h1>กรอกข้อมูลผู้ใช้</h1></label>
<input type="text" class="form-control" ng-model="formdata.Firstname" name="inputFirstname" placeholder="ชื่อจริง" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Lastname" name="inputLastname" placeholder="นามสกุล" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Username" placeholder="Username" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="password" class="form-control" ng-model="formdata.Password" placeholder="Password" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="password" class="form-control" ng-model="formdata.ConfirmPassword" placeholder="Password อีกครั้ง" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Email" name="inputEmail" placeholder="E-Mail" >
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.Tel" name="inputTel" placeholder="โทรศัพท์">
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="text" class="form-control" ng-model="formdata.CafeName" name="inputCafeName" placeholder="ชื่อร้าน">
</div>
<div class="form-group col-md-6 col-xs-12 col-md-offset-3">
<input type="hidden" ng-model="table" value="cafe">
<input type="hidden" ng-model="ajouter" value="1" >
<input ng-model="insertuser" ng-show="formdata.Firstname.length && formdata.Lastname.length && formdata.Username.length && formdata.Password.length &&
formdata.ConfirmPassword.length && formdata.Email.length && formdata.Tel.length && formdata.CafeName.length" ng-click="SignUp();" type="submit" value="insert" class="btn btn-primary">
<!--<input ng-model="insertuser" ng-click="SignUp();" type="submit" value="insertt" class="btn btn-primary">-->
</div>
</form>
<!--<input type="text" ng-model="cafe_id" value="" placeholder="CafeId"></br>
<input type="text" ng-model="CafeName" value="" placeholder="CafeName"></br>
<input type="text" ng-model="Username" value="" placeholder="Username"></br>
<input type="text" ng-model="CafeUrl" value="" placeholder="CafeUrl"></br>
<input type="hidden" ng-model="table" value="cafe">
<input type="hidden" ng-model="ajouter" value="1" >
<input ng-hide="update" ng-click="SignUp();" type="submit" value="insert" class="btn btn-primary">
<input ng-show="update" ng-click="update();" type="submit" value="update" class="btn btn-primary">
<input ng-click="getData();" type="submit" value="get" class="btn btn-primary">-->
<table border="1">
<tr ng-repeat="x in content">
<td>{{x.id}}</td>
<td>{{x.CafeName}}</td>
<td><button ng-click="editData(x.id)" >Edit</button></td>
<td><button ng-click="deleteData(x.id)" >Del</button></td>
</tr>
</table>
</form>
</div>
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods : GET,POST,PUT,DELETE,OPTIONS");
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Requested-With, X-YOUR-CUSTOM-HEADER');
header("Content-Type : application/json");/*or whatever type is relevant */
header("Accept : application/json");
$serverName = "localhost";
$userName = "root";
$userPassword = "";
$dbName = "middlework";
$conn = new mysqli($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($conn,"utf8");
session_start();
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$strSQL = "INSERT INTO users ";
$strSQL .="(Username,Password,Firstname,Lastname,Email,Tel,AccountStat,VerifyCode,Verifystat) ";
$strSQL .="VALUES ";
$strSQL .="('".$request->Username."','".$request->Password."','".$request->Firstname."' ";
$strSQL .=",'".$request->Lastname."','".$request->Email."','".$request->Tel."','User','".session_id()."','None') ";
#$findmax = "SELECT MAX(cafe_id) FROM cafe where Username = 'kkk'";
#$max = $conn->query($findmax);
#$row = mysqli_fetch_assoc($max);
#while ($row = mysqli_fetch_assoc($max)) {
# echo $row['cafe_id'];
#}
mysqli_query($conn,$strSQL);
/*if(mysqli_query($conn,$strSQL))
{
echo "Save User Done.[".$strSQL."]";
}
else
{
echo "Error Save [".$strSQL."]";
}*/
$insertcafe = "INSERT INTO cafe (cafe_id,Username,CafeName) VALUES ('1' , '".$request->Username."', '".$request->CafeName."')";
if($conn->query($insertcafe))
{
echo "Save Cafe Done.[".$insertcafe."]";
}
else
{
echo mysqli_error($conn);
echo "Save Cafe Fail[".$insertcafe."]";
}
require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "kitsakorn.p55@rsu.ac.th"; // GMAIL username
$mail->Password = "1100501068349"; // GMAIL password
$mail->From = "kitsakorn.p55@rsu.ac.th"; // "name@yourdomain.com";
$mail->FromName = "ThaiCoffeeShopOnline"; // set from Name
$mail->Subject = "ยืนยันการสมัครสมาชิก ThaiCoffeeShopOnline";
$mail->Body = "ขอขอบคุณที่สมัครเป็นสมาชิกกับเรา กรุณาคลิก Url ด้านล่างเพื่อทำการ Activate บัญชีของคุณ</br>
http://localhost/activate.php?sid=".session_id()."&uid=".$request->Username."</br></br> ThaiCoffeeShop.com";
$mail->AddAddress($request->Email); // to Address
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
//json_decode();
}
/*for ($i=1;$i<100;$i++){
$insertcafe = "INSERT INTO cafe (cafe_id,Username,CafeName) VALUES ('".$i."' , 'kkk', '".$request->CafeName."')";
#$queryy = $conn->query($insertcafe);
if($conn->query($insertcafe))
{
echo "Save Cafe Done.[".$insertcafe."]";
break;
}
else
{
echo mysqli_error($conn);
echo "Save Cafe Fail.".$i."[".$insertcafe."]";
}
echo $request->CafeName;
}*/
$conn->close();
?>
'use strict';
// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.viewLogin',
'myApp.SaveCafeDetail',
'myApp.version'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider.otherwise({redirectTo: '/view1'});
}]);