保存输入中的答案 - php



我尝试使用$ _POST,$ _GET和$ _REQUEST但它们都不起作用。我应该使用什么来保存输入中的答案?

<!DOCTYPE html> 
<html> 
<head> <title>Sign Up</title> </head> 
<body> 
<form method="POST"> 
<input type="text" name="first" id='first'> 
<input type="text" name='last' id='last'> 
<button type='submit' name='submit'>Click</button> 
</form> //WHERE THE INFORMATION IS ASKED 
<?php //WHERE I ATTEMPT TO SAVE THE INFORMATION BUT I FAIL 
include_once 'dbh.inc.php'; 
$first = $_POST['first']; 
$last = $_POST['last']; 
/*Notice: Undefined index: first in C:xampphtdocsindex.php on line 14 Notice: Undefined index: last in C:xampphtdocsindex.php on line 15*/ 
$sql = "INSERT INTO keep1(Firstname, Lastname) VALUES('$first', '$last');"; mysqli_query($conn, $sql); ?> 
</body> 
</html> 

附片段:

<!DOCTYPE html> <html> <head> <title>Sign Up</title> </head> <body> <form method="POST"> <input type="text" name="first" id='first'> <input type="text" name='last' id='last'> <button type='submit' name='submit'>Click</button> </form> //WHERE THE INFORMATION IS ASKED <?php //WHERE I ATTEMPT TO SAVE THE INFORMATION BUT I FAIL include_once 'dbh.inc.php'; $first = $_POST['first']; $last = $_POST['last']; /*Notice: Undefined index: first in C:xampphtdocsindex.php on line 14 Notice: Undefined index: last in C:xampphtdocsindex.php on line 15*/ $sql = "INSERT INTO keep1(Firstname, Lastname) VALUES('$first', '$last');"; mysqli_query($conn, $sql); ?> </body> </html>

你应该照顾好你的代码,让它易于阅读。所以其他人可能会阅读你的代码。

请尝试此操作,可能会出现错误,因为您尚未发布数据。

<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
</head>
<body>
<form method="POST">
<input type="text" name="first" id="first">
<input type="text" name="last" id="last">
<button type="submit">Click</button>
</form>
<?php
include_once 'dbh.inc.php';
if(isset($_POST['first']) && isset($_POST['last'])){
$first = $_POST['first'];
$last = $_POST['last'];
$sql = "INSERT INTO keep1(Firstname, Lastname) VALUES('$first', '$last');";
mysqli_query($conn, $sql);
}
?>
</body>
</html> 

最新更新