今天自己琢磨了半天愣是没有想出来,是想分别判断用户名和密码是否正确
自己写的代码如下:
$user = $_POST["user"];
$pwd = $_POST["pwd"];
$str=mysql_query("SELECT * FROM member WHERE user = '$user' AND pwd='$pwd'");
$line=mysql_fetch_array($str);
if($line[1] && $line[2]){
echo "账号密码正确";
}else if(!$line[1]){
var_dump($line[1]);
echo "账号错误";
}else if(!$line[2]){
echo "密码错误";
}
希望有大神可以解答
回复讨论(解决方案)
你写两条sql呀,一个传用户名,一个传密码,分别判断两个sql查出来的两个结果
应该是写2个判断:
1、sql是判断是否用户名
SELECT * FROM member WHERE user = '$user'
2、SELECT * FROM member WHERE user = '$user' AND pwd='$pwd'
如果第一个对了,代表用户名对的,第二个错了,就代表密码这个用户名密码错了
首先是两者不能为空,然后判断用户名是否存在,密码和用户名都正确,成功。
两条SQL,一条查询用户名是否存在,一条查询用户名密码是否正确
假定你代码中的对应关系是正确的
$user = $_POST["user"];$pwd = $_POST["pwd"];$str = mysql_query("SELECT * FROM member WHERE user = '$user' or pwd='$pwd'");$line = mysql_fetch_array($str);if($line[1] == $user && $line[2] == $pwd){ echo "账号密码正确";}else if($line[1] != $user){ var_dump($line[1]); echo "账号错误";}else if($line[2] != $pwd){ echo "密码错误";}

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
