search
HomeBackend DevelopmentPHP ProblemPHP failed to write to mysql database

PHP failed to write to mysql database

Oct 21, 2019 am 09:45 AM
mysqlphpfail

PHP failed to write to mysql 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 mysql_query cannot be used to insert data into the database.

There are many situations when you encounter 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();
    }

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"); it can be solved by adding your own mysql encoding method after the names.

Recommended tutorial: PHP video tutorial

The above is the detailed content of PHP failed to write to mysql database. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools