我的php文件没有将HTML表单中的信息插入到我的数据库表中。
我从错误消息中显示的表格中收到信息,我在MAMP上运行。
<?php
$server_name = "localhost:2243";
$username = "root";
$password = "root";
$dbname = "studentinfo";
$conn = mysqli_connect($server_name,$username,$password,$dbname);
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
//retrieving the data
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$school = $_POST['field4'];
$sql = "INSERT INTO studentlist (firstname,lastname,email,school)
VALUES ('$first_name','$last_name','$email','$school')";
if(mysqli_query($conn, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
?>
这是我正在使用的表格
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Submission Form</title>
<meta name="description" content="DESCRIPTION">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src = "http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="form-style-5">
<form action="addData.php" method="post">
<fieldset>
<legend><span class="number">1</span> Candidate Info</legend>
<input type="text" name="firstname" id="firstname" placeholder="Your First Name *">
<input type="text" name = "lastname" id="lastname" placeholder="Your Last Name" />
<input type="email" name="email" id="email" placeholder="Your Email *">
<label for="school">Your School</label>
<select id="school" name="field4">
<optgroup name = "school" label="School">
<option value="LHS">Lisnaskea High School</option>
<option value="Potora">Potora Royal Grammer</option>
<option value="OU">The Open University</option>
</optgroup>
</select>
</fieldset>
<input type="submit" name="submitstudent" value="submit" onclick="return validate()"/>
</form>
</div>
答案 0 :(得分:1)
发布为社区维基。不应该有任何代表。
&#34;问题是服务器名称,因为我删除了端口号感谢评论@ Fred-ii- - bighead 1分钟前&#34;
&#34; @bighead Aahhhhh我应该更早地跟随我的另一种本能,作为端口! aughh!大声笑,嘿,欢迎你。 - 弗雷德-ii- 27秒前&#34;
所有这一切的答案都是删除端口号:
$server_name = "localhost";
而不是:
$server_name = "localhost:2243";