简体   繁体   English

无法在数据库的表中插入值

[英]Not able to insert values in table in database

I am trying to insert values in database ,but not able to do that 我正在尝试在数据库中插入值,但无法做到这一点

<?php
if(isset($_POST['submit']))
{
$fullname=$_POST['fullname'];
$contactnumber=$_POST['contactnumber'];
$email=$_POST['email'];
$qualification=$_POST['qualification'];
$postappliedfor=$_POST['postappliedfor'];
$sql_connection=mysql_connect("localhost","root","admin","interview");
mysql_select_db("interview,$sql_connection") or die("cannot select DB");
$sql=mysql_query("INSERT INTO `USERDEATILS`(`id`,`fullname`,`contactnumber`,`email`,`qualification`,`postappliedfor`) VALUES('','$fullname','$contactnumber','$email','$qualification','$postappliedfor')");
if($sql){
        echo "done";
    }
    else{
        echo "There is an error!!"; 
    }
}


?>

change the line mysql_select_db("interview,$sql_connection") 更改行mysql_select_db(“ interview,$ sql_connection”)

to

mysql_select_db("interview", $sql_connection) mysql_select_db(“访问”,$ sql_connection)

In addition to what Manuel Ramirez said, you might want to check to make sure your mysql data type 'id' isn't set to NOT NULL. 除了Manuel Ramirez所说的以外,您可能还需要检查以确保您的mysql数据类型'id'未设置为NOT NULL。 You also may want add the to auto_increment property to the 'id' field, so you can ommit it when inserting records 您可能还希望将to_auto_increment属性添加到“ id”字段,以便在插入记录时可以将其省略

Use proper syntax of mysql : 使用mysql的正确语法:

$sql_connection = mysql_connect('localhost', 'mysql_user', 'mysql_password');

remove database_name from mysql_connect . mysql_connect删除database_name

In mysql_connect we can only pass 5 parameters : mysql_connect我们只能传递5参数

  1. Server 服务器
  2. username 用户名
  3. password 密码
  4. new_link new_link
  5. client_flags client_flags

But i will suggest you to use MySQLi that would be like this: 但我建议您使用像这样的MySQLi:

$connection = mysqli_connect('localhost', 'username', 'password', 'database');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM