0
有人可以幫我解決這個問題嗎? 我有一個3 INT列(danni,lenni,anders)表。我希望這個表單插入一個新行,並在每次使用時在字段中寫入數字。它確實插入了一個新行,但無論輸入什麼數字,只在表中插入「0」。通過HTML INSERT INTO
<?php
// Connection
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$danni = mysqli_real_escape_string($link, $_REQUEST['danni']);
$lenni = mysqli_real_escape_string($link, $_REQUEST['lenni']);
$anders = mysqli_real_escape_string($link, $_REQUEST['anders']);
// attempt insert query execution
$sql = "INSERT INTO ligabs3 (danni, lenni, anders) VALUES ('$danni', '$lenni', '$anders')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Records Form</title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>
<label for="danni">Danni:</label>
<input type="text" name="danni" id="danni">
</p>
<p>
<label for="lenni">Lenni:</label>
<input type="text" name="lenni" id="lenni">
</p>
<p>
<label for="anders">Anders:</label>
<input type="text" name="anders" id="anders">
</p>
<input type="submit" value="Add Records">
</form>
</body>
</html>
瞭解準備好的發言 – Jens
'$ _REQUEST'必須是'$ _POST' – Jens
你在一個文件中使用此,所以它的自動只要你加載它就插入0。使用'!empty()'/'isset()'。 –