<html>
<head>
<script src="check.js"></script>
<title>Sign Up</title>
</head>
<body>
<div id="container">
<div id="child"
<form action="insert.php" method="post">
<br /><br />
<input type="text" placeholder="Firstname" name="fn" maxlength="12"
autofocus/> <br /><br />
<input type="text" placeholder="Lastname" name="ln" maxlength="12" /> <br
/><br />
<input type="text" placeholder="username/student id" name="sid"
maxlength="12" /> <br /><br />
<label>
<input placeholder="password" name="password" id="password"
type="password" />
</label>
<br></br>
<label>
<input placeholder="confirm password" type="password"
id="confirm_password" onkeyup='check();'/>
<br></br>
<span id='message' ;"></span>
</label>
<br /><br />
<input class="form-submit-button" type="submit" value="Sign in">
</form>
</div>
</div>
</body>
</html>
此html页面应收集用户详细信息并将其链接到php文件,即insert.php
insert.php
<?php
$link = mysqli_connect("localhost", "root", "root", "demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "INSERT INTO student_details VALUES ($_POST['sid'],
$_POST['fn'], $_POST['ln'], $_POST['password'])";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
此文件从表单中收集数据并将其插入表中。当我在html页面填写表格并提交时,没有任何事情发生。当我在localhost中单独执行代码时,它正在处理静态值。我是php和html的新手。我无法找到错误。