请忽略界面和库存的数量(仅供测试使用),本人初学者
如图所示,题主想实现的功能如下:
在AllItems.php单击查看详情,跳转到Test.php
Test.php是商品详情页面,用户输入购买数量,单击ok实现数据库库存的减少
Test.php代码如下
<code> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <form action="#" method="post" onsubmit="check()"> <input type="text" name="num" id="num"> <input type="submit" value="ok"> </form> <script type="text/javascript"> function check(){ </script> <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("user_info"); $number = $_POST["num"]; $sql="select * from inventory where pid = '1'"; $sql2 = "update inventory set pnum = pnum-'$number' where pid = '1' "; $query=mysql_query($sql); $query2=mysql_query($sql2); $result = mysql_fetch_array($query); @$pnum = $result['pnum']; if (isset($_POST["num"])&&$_POST["num"]!=""&&$_POST["num"]<=$pnum){ echo "<script>alert('添加成功')"; }else if(isset($_POST["num"])&&$_POST["num"]!=""&&$_POST["num"]>$pnum){ echo "<script>alert('illegal input')</script>"; }else{ } ?> <script type="text/javascript"> } </script> </code>
目前有以下几个问题,
1.每次进入页面都会输出illegal input,我知道这与执行顺序有关,但是是否有某种方式控制这段代码的执行,比如isset?
2.目前已经可以实现库存按照用户输入减少,但是判断用户输入合法性(忽略字符之类)只比较用户输入与库存大小,这个功能并不能实现,请求指教。
再次声明 我是初学者
回复内容:
请忽略界面和库存的数量(仅供测试使用),本人初学者
如图所示,题主想实现的功能如下:
在AllItems.php单击查看详情,跳转到Test.php
Test.php是商品详情页面,用户输入购买数量,单击ok实现数据库库存的减少
Test.php代码如下
<code> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <form action="#" method="post" onsubmit="check()"> <input type="text" name="num" id="num"> <input type="submit" value="ok"> </form> <script type="text/javascript"> function check(){ </script> <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("user_info"); $number = $_POST["num"]; $sql="select * from inventory where pid = '1'"; $sql2 = "update inventory set pnum = pnum-'$number' where pid = '1' "; $query=mysql_query($sql); $query2=mysql_query($sql2); $result = mysql_fetch_array($query); @$pnum = $result['pnum']; if (isset($_POST["num"])&&$_POST["num"]!=""&&$_POST["num"]<=$pnum){ echo "<script>alert('添加成功')"; }else if(isset($_POST["num"])&&$_POST["num"]!=""&&$_POST["num"]>$pnum){ echo "<script>alert('illegal input')</script>"; }else{ } ?> <script type="text/javascript"> } </script> </code>
目前有以下几个问题,
1.每次进入页面都会输出illegal input,我知道这与执行顺序有关,但是是否有某种方式控制这段代码的执行,比如isset?
2.目前已经可以实现库存按照用户输入减少,但是判断用户输入合法性(忽略字符之类)只比较用户输入与库存大小,这个功能并不能实现,请求指教。
再次声明 我是初学者
就标题而言,减少库存需要在前端表现出来以及把数据同步到服务端,ajax是一个很好的选择

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

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


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

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.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
