php - 使用 html 表单 (MYSQL/PHP) 将记录插入数据库

标签 php mysql html database

正如标题所说,我正在尝试通过 html 表单将记录插入 mysql 数据库。

这是文件的 html 表单部分:Addstudent.html

/div>
<div id="main">
    <h2>Add another student?</h2>
    <p>Please fill out the requested fields.</p>
   <form action="Insertstudent.php" method="post">
  StudentId:     <input type="text" name="studentid"><br>
  Password:      <input type="text" name="password"><br>
  Dob:           <input type="text" name="dob"><br>
  Firstname:     <input type="text" name="firstname"><br>
  Surname:       <input type="text" name="surname"><br>
  Address:       <input type="text" name="address"><br>
  Town:          <input type="text" name="town"><br>
  County:        <input type="text" name="county"><br>
  Country:       <input type="text" name="country"><br>
  Postcode:      <input type="text" name="postcode"><br>
  <input type="Submit">

这是文件 Insertstudent.php 的一部分

<?php
// Insert record using this script

session_start();
include("dbconnect.inc");


// If the form has been submitted
if ($_POST[submit]){
// Build an sql statment to insert a new student to the database
$sql="INSERT INTO student values '" . $_SESSION[id] ."' . '$_POST[studentid]'.'$_POST[password]' . '$_POST[dob]' . '$_POST[firstname]' . '$_POST[lastname]' . '$_POST[house]' . '$_POST[county]' . '$_POST[country]' . '$_POST[postcode]')";
$result = mysql_query($sql,$conn);
 ?>

我遇到的主要问题是插入脚本 - 我显然做错了什么,因为我的数据库没有更新。

预先感谢任何回复此问题的人 - 非常感谢。

最佳答案

用逗号而不是句点分隔要插入的值。例如:

INSERT INTO table_name
VALUES (value1, value2, value3,...)

关于php - 使用 html 表单 (MYSQL/PHP) 将记录插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6009765/

相关文章:

php - 用php返回json数据

php - 在 Laravel 3 中,带有自定义表的模型不会保存

javascript - 添加和删​​除类不同的元素

php - doctrine 2 和 zend framework 2 如何使用缓存?

php sql 连接类型

c# - 连接关闭后,MySql 临时表仍然存在(来自.NET)

php - MySQL默认值不正确

php - mysql查询没有显示正确的提交按钮?

html - 使用ruby从html文档中删除空格

php - 如何从我的数据库中检索数据?