What to do if php cannot insert data

藏色散人
Release: 2023-03-04 17:28:01
Original
3707 people have browsed it

Solution to the problem that php cannot insert data: first check whether the sql statement can run normally in the Mysql command line; then use the "mysql_query" method to check the error message; and finally reset the encoding method.

What to do if php cannot insert data

Recommended: "PHP Video Tutorial"

Solution to PHP connection to Mysql but unable to insert Data into the database

When writing a web page, under certain circumstances, mysql_connect may connect to the database, and mysql_select_db selects the correct table, but it cannot use mysql_query to insert data into the database. .

There are many situations when encountering this situation. First, you have to check whether your sql statement can run normally in the Mysql command line and whether it can complete the function. If it can run normally, it means that your sql statement is correct. Then use

  $res = mysql_query($sql, $con);
   if($res){
       echo "插入成功";
   }
    else{
     echo mysql_error();
    }
Copy after login

to solve the problem based on the error message. If mysql_error() cannot be displayed; it may be a coding error. Add mysql_query( "set names GBK"); add your own mysql encoding after the names.

The above is the detailed content of What to do if php cannot insert data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template