php - MySQL 数据库保存 0 个值

标签 php mysql database forms submit

我有一个表格来统计我大学的类(class)注册,其中一个字段是“studentid”,将表格连接到数据库似乎是成功的,并且自动递增的主要字段工作正常,但是输入学生 ID 和提交表格每次都失败,并且添加了一 strip 有“0”值的新记录......

这是html代码

     <div class="content">

    <form action="connect-mysql.php" method="POST" enctype="text/plain" id="form3" name="form3" method="post">

    <table width="100%" border="0">
      <tr>
        <td width="50%" bgcolor="#e3e3e3"><center>
        Student ID :
        </center></td>
        <td width="50%" bgcolor="#e3e3e3">
          <span id="sprytextfield1">
          <label for="studentid"></label>
          <input name="studentid" type="text" id="studentid" onblur="MM_validateForm('studentid','','NisNum');return document.MM_returnValue" maxlength="11" />
*<span class="textfieldRequiredMsg">A value is required.</span></span>
        </td>

PHP代码

<?php
$host="fdb7.biz.nf" ;`enter code here`
$username="1662822_db1" ;
$password="421343" ;
$db_name="1662822_db1" ;
$tbl_name="courses" ;
    $dbcon = mysqli_connect("$host","$username","$password","$db_name") ;           

    if (!$dbcon) {
    die('error connecting to database'); }

    echo 'you have connected sucessfully' ; 

// escape variables for security
$studentid = mysqli_real_escape_string($dbcon, $_POST['studentid']);

$sql="INSERT INTO courses (studentid)
VALUES ('$studentid')";

if (!mysqli_query($dbcon,$sql)) {
die('Error: ' . mysqli_error($dbcon));
 }
 echo "1 record added"; 
    mysqli_close($dbcon);
  ?>

最佳答案

method="POST"

以形式重复

这样检查学生id:

$studentid = mysqli_real_escape_string($dbcon, $_POST['studentid']); echo $studentid;

设置后可以打印$sql变量到

关于php - MySQL 数据库保存 0 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23301789/

相关文章:

mysql - 从 CSV 到 MySQL 的特殊字符不起作用?

带有 mySQL 的 PHP 对象数组

php - 计算两个时间戳之间停电的Mysql查询

php - Swift SHA256 哈希与 PHP SHA256 哈希不匹配

php - 组织这些表+行的最有效方法是什么? - MySQL

php - 我如何将目录变成可以轻松更新的数据库?

php - 使用单选按钮增加 MySql 数据库中的值

java - 嵌入式 Java 数据库允许从不同 JVM 实例并发读取?

php - 使用 PDO 计算每个页面加载的查询数

php - JOIN 查询未产生正确的结果