I made a short-answer verification code. At first, there was only an input box for the verification code and a verification code image. After submission, you can print out whether the verification code you entered is correct or wrong. Later, I added a text box. I want to make a simple verification submission with a few SQL statements, but I don’t know how to verify it. In practice, it must not just prompt an error or correct it. If there is an error, how should I prevent the form from being submitted? Another problem that needs to be solved first is that the verification code itself does not need to be inserted into the database, but there is a name in the form of the verification code. If the SQL statement is not processed and click submit, an error will be reported. What should I do? Invalid parameter number: number of bound variables does not match number of tokens in D:wampwwwyzm1.php on line 28
<code><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <form method="post"> <input type="text" name="num"><br /> <input type="text" style="display: inline-block;width: 50px;" name="yzm"> <img id="checkpic" onclick="javascript:this.src='yzm2.php?tm='+Math.random();" src='yzm2.php' /> <button type="submit">提交</button> </form> <?php if(trim(@$_POST['num'])){ session_start(); if(isset($_POST['yzm'])){ if($_SESSION["str"]==$_POST['yzm']){ echo "right"; }else{ echo "wrong"; } } $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $stmt=$pdo->prepare("insert into test(num)values(:num)"); $stmt->execute($_POST); } ?> </body> </html> </code>
I made a short-answer verification code. At first, there was only an input box for the verification code and a verification code image. After submission, you can print out whether the verification code you entered is correct or wrong. Later, I added a text box. I want to make a simple verification submission with a few SQL statements, but I don’t know how to verify it. In practice, it must not just prompt an error or correct it. If there is an error, how should I prevent the form from being submitted? Another problem that needs to be solved first is that the verification code itself does not need to be inserted into the database, but there is a name in the form of the verification code. If the SQL statement is not processed and click submit, an error will be reported. What should I do? Invalid parameter number: number of bound variables does not match number of tokens in D:wampwwwyzm1.php on line 28
<code><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <form method="post"> <input type="text" name="num"><br /> <input type="text" style="display: inline-block;width: 50px;" name="yzm"> <img id="checkpic" onclick="javascript:this.src='yzm2.php?tm='+Math.random();" src='yzm2.php' /> <button type="submit">提交</button> </form> <?php if(trim(@$_POST['num'])){ session_start(); if(isset($_POST['yzm'])){ if($_SESSION["str"]==$_POST['yzm']){ echo "right"; }else{ echo "wrong"; } } $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $stmt=$pdo->prepare("insert into test(num)values(:num)"); $stmt->execute($_POST); } ?> </body> </html> </code>
<code><?php if(trim(@$_POST['num'])){ session_start(); if(isset($_POST['yzm'])){ if($_SESSION["str"]==$_POST['yzm']){ echo "right"; $pdo=new PDO("mysql:host=localhost;dbname=t1","root",""); $stmt=$pdo->prepare("insert into test(num)values(:num)"); $stmt->execute(array(':num'=>$_POST['num']); }else{ echo "wrong"; } } } ?> </code>
Just write like this