用的ajax;
前台编码utf-8,用jquery的post传到后台,写入数据库后中文乱码,请问应该怎么设置编码或者转码。
$(document).ready(function(){ $("#usersubmit").click(function(){ $.post("addsinger.php", { singername : $("#singername").val() , area : $("#area").val() , sex : $("#sex").val() , singerimg : $("#singerimg").val() , singercid : $("#singercid").val() , singerfirstword : $("#singerfirstword").val() }, function (data, textStatus){ if(data=="success"){ window.location.reload() } } ); }) });
$singername=$_POST['singername'];$area=$_POST['area'];$sex=$_POST['sex'];$singercid=$_POST['singercid'];$singerimg=$_POST['singerimg'];$singerfirstword=$_POST['singerfirstword'];$connstr="DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath("../mtv.mdb");$conn=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC );$sql = "INSERT INTO singer (singer,singerarea,singersex,singercid,singerimg,singerfirstword) VALUES ('$singername','$area','$sex','$singercid','$singerimg','$singerfirstword')";$rs=odbc_do($conn,$sql);echo "success";
还有一个,后台怎么确定这一条记录成功是否被写入,然后返回一个布尔值。
回复讨论(解决方案)
表是什么编码?
addsinger.php 文件的编码格式 和数据库的编码格式。请确定
ajax 总是以 utf-8 发送数据
access 只有 gbk 和 unicode 两种编码

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
