请教一个简单的投票页面,post怎么写
以前写过一个简单的投票功能,作用是php post值 如果和数据库内容一致,则count+1 截图如下
<form method="post" action="check.php"> <br /><input type="text" name="test"> <br /><br /><input type="hidden" name="action" value="send"> <br /><input type="submit" name="Submit" value="提交"> <br /></form> <br /><br /><?php<br />$conn = mysql_connect("127.0.0.1:8889","root","root"); <br />$action = $_POST['action']; <br />if($action == 'send'){ <br />$test = $_POST['test']; <br /><br />mysql_select_db("test3",$conn); <br />$sql = ("update tll set count=count+1 where tl01='$test'");<br />$result = mysql_query($sql,$conn); <br />} <br />?>

现在希望把check.php由原来的单个框改成多个进行投票

<br /><form method="post" action="check.php"> <br /><input type="text" name="test[]"> <br /><br /><input type="text" name="test[]"> <br /><br /><input type="text" name="test[]"> <br /><br /><input type="hidden" name="action" value="send"> <br /><input type="submit" name="Submit" value="提交"> <br /></form> <br /><br /><?php<br />$conn = mysql_connect("127.0.0.1:8889","root","root"); <br />$action = $_POST['action']; <br />if($action == 'send'){ <br />$test = $_POST['test[]']; <br /><br />mysql_select_db("test3",$conn); <br />$sql = ("update tll set count=count+1 where tl01='$test'");<br />$result = mysql_query($sql,$conn); <br />} <br />?>的话就完全行不通了 ,实在不懂,请大神帮忙看下改下代码,十分感谢!
再问下,数据库的格式是“1空格1空格1” 这个格式是固定的
投票页面 如果投票成功,数据库的count的确+1的话echo投票成功,如果不成功(比如格式错了,或者填写错误)echo
投票失败,,这个怎么做呢?90分献上,望指教!
------解决思路----------------------
$_POST['test[]']是获取不到值的,你需要获取$_POST['test'],它的值是个数组,比如可能是:
array('111', '222','333')
然后你需要对数组进行遍历,插入到数据库中,你的数据库不能单纯的用等于号来获取:
tl01='$test'"
mysql没有这种语句,mysql处理多个语句需要用in操作:
where tl01 in ('111', '222', '333')
所以,你需要把数组转换成mysql需要的字符串:('111', '222', '333'),才能实现你的功能
------解决思路----------------------
$conn = mysql_connect("127.0.0.1:8889","root","root"); <br />$action = $_POST['action']; <br />if($action == 'send'){ <br /> $test = join("','", $_POST['test']);<br /> <br /> mysql_select_db("test3",$conn); <br /> $sql = ("update tll set count=count+1 where tl01 in ('$test')");<br /> $result = mysql_query($sql,$conn); <br />}
------解决思路----------------------
不一定买书,上网多查查资料啊,主要是mysql相关的知识,你要学习mysql语法,就会了

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad


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

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools
