使用jquery进行验证(validation using jquery)
下面的链接有我的网页,我想验证所有使用jQuery的字段,问题是我没有太多的空间周围的领域来显示普通的错误消息。 我是一个新手,并且正在考虑使用jquery验证,所以你们中的任何一个人都可以建议我以最好的方式来做到这一点。 http://www.4shared.com/photo/BowU9nFB/page.html
感谢您,
Indranil
The below link has my web page and i would like to validate all the fields using jquery, the problem is I dont have much space around the fields to display ordinary error messages. I am am a novice and thinking of using jquery validation, so could any of you suggest me the best possible way to do that. http://www.4shared.com/photo/BowU9nFB/page.html
Thanking You,
Indranil
原文:https://stackoverflow.com/questions/2775663
最满意答案
概述代码中的错误,并提供经过测试的工作解决方案:
- 你正在调用
prepare()
函数两次。- 为SELECT使用错误的变量。
...使用$sql
,它应该是$stmt
- 不可能调用你的
getManger()
函数。- 使用连字符而不是等号
$age - $row['age'];
=>$age = $row['age'];
改写:
<?php $db_host = "localhost"; $db_username = "root"; $db_pass = ""; $db_name = "testdb"; $dbh = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); function getManger($dbh) { $stmt= $dbh->prepare("SELECT * FROM test_tbl"); $stmt->execute(); while( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) { $id = $row['id']; $name = $row['name']; $age = $row['age']; echo "<li>$id</li>"; echo "<li>$name</li>"; echo "<li>$age</li>"; } } // call the function getManger($dbh);
脚注 :
通常最好将你的数据库连接变量传递给你的函数,而不是把它变成全局变量。
以下是关于全球的Stack上的一些文章:
这是你的选择。
To outline the errors in your code, and offer a tested and working solution:
- You're calling the
prepare()
function twice.- Using the wrong variable for your SELECT.
...using$sql
where it should be$stmt
- Not possibly calling your
getManger()
function.- Using a hyphen instead of an equal sign
$age - $row['age'];
=>$age = $row['age'];
Rewrite:
<?php $db_host = "localhost"; $db_username = "root"; $db_pass = ""; $db_name = "testdb"; $dbh = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); function getManger($dbh) { $stmt= $dbh->prepare("SELECT * FROM test_tbl"); $stmt->execute(); while( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) { $id = $row['id']; $name = $row['name']; $age = $row['age']; echo "<li>$id</li>"; echo "<li>$name</li>"; echo "<li>$age</li>"; } } // call the function getManger($dbh);
Footnotes:
It's usually best to pass your DB connection variable inside your function, rather than making it global.
Here are a few articles on Stack about global:
The choice is yours.
相关问答
更多-
你忘了执行准备好的陈述。 在使用$stmt->fetch ()之前请使用$stmt->execute () $stmt->fetch () 也请像这样取: $requests = $stmt->fetch (PDO::FETCH_ASSOC); foreach ($requests as $request) { echo $request["whateverKeyYouWant"]; } You forgot to execute your prepared statement. Pleas ...
-
如评论中所述: 这是表语法的示例
ABC 123
'; As stated in comments: This is an ...'.$row['lastLogin'].' -
一些很好的旧动态SQL查询拼凑在一起... $sql = sprintf('SELECT * FROM user WHERE name LIKE :name %s %s', !empty($_GET['city']) ? 'AND city = :city' : null, !empty($_GET['gender']) ? 'AND gender = :gender' : null); ... if (!empty($_GET[' ...
-
PDO结果为空(PDO results are empty)[2023-04-13]
您正在为$bind_array和$bnid_array分配值,但是将$bind_arguments发送到execute() 。 尝试将$bnid_array更改$bnid_array $bind_array并使用$stmt->execute($bind_array); You are assigning values to $bind_array and $bnid_array but are sending in $bind_arguments to execute(). Try changing $bn ... -
概述代码中的错误,并提供经过测试的工作解决方案: 你正在调用prepare()函数两次。 为SELECT使用错误的变量。 ...使用$sql ,它应该是$stmt 不可能调用你的getManger()函数。 使用连字符而不是等号$age - $row['age']; => $age = $row['age']; 改写:
显示来自PDO的结果(Display Results from PDO)[2023-08-08]
如果尝试echo $fruit->'fruitName'出现任何错误,请尝试通过数组访问它,如$fruit['fruitName'] 。 这就是PDO的fetchAll()方法返回结果的方式。 但是,您还可以通过传递PDO::FETCH_CLASS作为fetchAll()方法的第一个参数,并将类名作为第二个参数来指定您想要一个对象数组。 看到这里: http : //php.net/manual/fr/pdostatement.fetchall.php 希望这可以帮助 ! If you have any e ...准备好的语句不会在查询数据中添加斜杠。 它们以占位符的形式将参数注入查询,这样占位符不会被视为查询的一部分,而只是作为数据的一部分。 因此,不会添加任何斜线,也不需要stripslashes() 。 如果为您添加了斜杠,请确保为PDO实例禁用预准备语句仿真: $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); get_magic_quotes_gpc was indeed turned on even though WHM (cPanel) sai ...当你忘了解释你正在尝试什么是“这个”时,这里有两种可能的情况: 如果“this”用于从数据库获取所有记录,则代码将是 $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $stmt = $conn->query('SELECT * FROM portfolio'); while ( ...例。 这是你的dbc类 dbserv ...您在使用标头重定向之前发送了输出,要么使用输出缓冲,要么在将任何内容发送到客户端之前执行重定向 As Limiter said I needed to use output buffering to stop any printing/echoing before using header("Location:/login_check.php"); What I did was start the ob_start() right after session_start(), and ob_end_flu ...相关文章
更多- jquery 问题
- 用jquery validate封装自己的验证库
- jQuery中$与$()的区别?
- 找一个JQuery的控件
- jQuery Mobile 的特性
- 黑马的jquery教学视频
- jquery 插件开发
- jquery validate 插件实例教程
- Jquery EasyUI系列教程3
- jquery与servlet交互的json问题
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。