我做了一個網頁,從一個字符串中獲取他的數據從一個可視化的基本項目,並將其發送到MySQL。現在它已經運行他的PHP後關閉瀏覽器(Internet Explorer)。現在我找到了一種方法來關閉它,但沒有「腳本試圖關閉瀏覽器」Promt,但它太快並且數據永遠不會到達數據庫。我希望它等待(最好是直到PHP腳本完成,但如果不可能,那麼幾秒鐘)使javascript等待php
這裏是我的PHP:提前
<!DOCTYPE html>
<html>
<body>
<?php
//variabelen terughalen
$user = $_GET['userw'];
$ip = $_GET['ipw'];
$pc = $_GET['laptopw'];
$keuze = $_GET['keuzew'];
echo "$user <br> $ip <br> $pc <br> $keuze <br>";
//Serverside info
$servername = "172.17.80.153";
$username = "connect";
$password = "123456";
$dbname = "vbtest";
// Connectie maken
$conn = new mysqli($servername, $username, $password, $dbname);
// connectie testen
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully <br>";
//regels voor de lengte van variabelen
if (strlen($user) <> 4) { echo "geen veranderingen toegestaan";
die ;}
if (strlen($ip) > 14) { echo "geen veranderingen toegestaan";
die ;}
if (strlen($keuze) > 3) { echo "geen veranderingen toegestaan";
die ;}
if (strlen($keuze) < 2) { echo "geen veranderingen toegestaan";
die ;}
//Entry toevoegen aan de MySQL
if ($keuze == 'ja') {
$sql = ("INSERT INTO testtbl(Gebruikersnaam, Computernaam, Ipaddress, Keuze) VALUES('".$user."', '".$pc."', '".$ip."', '".$keuze."')");
}
else
{
$sql = ("INSERT INTO testntbl(Gebruikersnaam, Computernaam, Ipaddress, Keuze) VALUES('".$user."', '".$pc."', '".$ip."', '".$keuze."')");
$sql2 = ("INSERT INTO testtbl(Gebruikersnaam, Computernaam, Ipaddress, Keuze) VALUES('".$user."', '".$pc."', '".$ip."', '".$keuze."')");
if (mysqli_query($conn, $sql2)) {
echo "<br>New second record created successfully";
} else {
echo "Error: " . $sql2 . "<br>" . mysqli_error($conn);
}
}
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
?>
<script type="text/javascript">
window.open('javascript:window.open("", "_self", "");window.close();', '_self');
</script>
</body>
</html>
感謝
你在你的代碼都SQL注入和XSS漏洞。 – Boann 2014-10-30 14:27:03
一旦PHP完成,您將不得不返回客戶端。 – 2014-10-30 14:27:05
JavaScript已經「等待」了PHP,因爲在上面的代碼完成之前,PHP將不會回顯JavaScript,因此不能成爲數據庫插入不起作用的原因。 – Boann 2014-10-30 14:30:38