信息查询页面,怎么加入验证码

查询信息用的页面,php写的验证码,现在只能判断验证码是否正确,不能进行下一步操作。比如我输入了要查询的内容,再输入验证码,然后提交就只能判断验证码是否正确,不能查询到信息。要怎么写才能在判断验证码正确后,显示出相关信息呢。现在所有内容都做好了,没有验证码是可以查询的,问题就在验证码这一块儿

我大概明白你的问题。Follow me……
在这里写几个php文件来演示吧,一个是展示页index.php,另两个是处理文件index_ok.php、vcode.php。
index.php的代码如下:

function chkinput(form){ if(form.user.value==""){ alert("用户名不能为空!"); form.user.focus(); return false; } if(form.pwd.value==""){ alert("密码不能为空!"); form.pwd.focus(); return false; } if(form.vcode.value==""){ alert("验证码不能为空!"); form.vcode.focus(); return false; } if(form.vcode.value!=form.ycode.value){ alert("输入的验证码不正确!"); form.vcode.focus(); return false; } return true; }








用户名:

密 码:

验证码:

          var num1=Math.round(Math.random()*10000000+10000); var num=num1.toString().substr(0,4); document.write("<img name=c src='vcode.php?code="+num+"'>"); f.ycode.value=num; function recode(){ var num1=Math.round(Math.random()*10000000); var num=num1.toString().substr(0,4); document.c.src="vcode.php?code="+num; f.ycode.value=num; } 看不清?

      注册


接下来是处理文件index_ok.php和vcode.php。先看index_ok.php,代码如下:
<?php
header("content-type=text/html;charset=utf8");
include_once("conn.php");
$name=$_POST['user'];
$mima=$_POST['pwd'];
$r=mysql_query("select * from tb_admin where user='".$name."' and pwd='".$mima."'",$conn);//数据库的数据自己添加,这里我就不说了。
if(mysql_num_rows($r)>0){

echo "alert(&#39;登陆成功!&#39;);location=&#39;xxx.php&#39;;";
}else{

echo "alert(&#39;用户名或密码错误,请重试!&#39;);location=&#39;index.php&#39;;";
}
?>
再看vcode.php,代码如下:
<?php

header("Content-type:text/html;charset=utf8");

$im=imagecreate(60,20);

imagefill($im,0,0,imagecolorallocate($im,200,200,200));

$code=$_GET['code'];

for($i=0;$i<4;$i++){

$color=imagecolorallocate($im,rand(0,100),rand(0,100),rand(0,100));

imagestring($im, rand(3,5),60*$i/4+rand(3,6), rand(0,6), $code[$i], $color);

}

for($j=0;$j<200;$j++){

imagesetpixel($im,rand(0,60),rand(0,20),imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255)));

}

imagepng($im);

imagedestroy($im);

运行得到
Bingle!提交既能判断验证码是否正确,又能查询到信息。
希望我的解答能帮到你,如果还有什么疑问可以继续问我。
Love code,love life.

我大概明白你的问题。Follow me……
在这里写两个php文件来演示吧,一个是展示页index.php,一个是处理文件index_ok.php。
index.php的代码如下:

function chkinput(form){ if(form.user.value==""){ alert("用户名不能为空!"); form.user.focus(); return false; } if(form.pwd.value==""){ alert("密码不能为空!"); form.pwd.focus(); return false; } if(form.vcode.value==""){ alert("验证码不能为空!"); form.vcode.focus(); return false; } if(form.vcode.value!=form.ycode.value){ alert("输入的验证码不正确!"); form.vcode.focus(); return false; } return true; }








用户名:

密 码:

验证码:

          var num1=Math.round(Math.random()*10000000+10000); var num=num1.toString().substr(0,4); document.write("<img name=c src='vcode.php?code="+num+"'>"); f.ycode.value=num; function recode(){ var num1=Math.round(Math.random()*10000000); var num=num1.toString().substr(0,4); document.c.src="vcode.php?code="+num; f.ycode.value=num; } 看不清?

      注册


另一个就是处理文件index_ok.php,代码如下:
<?php
header("content-type=text/html;charset=utf8");
include_once("conn.php");
$name=$_POST['user'];
$mima=$_POST['pwd'];
$r=mysql_query("select * from tb_admin where user='".$name."' and pwd='".$mima."'",$conn);
if(mysql_num_rows($r)>0){

echo "alert(&#39;登陆成功!&#39;);location=&#39;xxx.php&#39;;";
}else{

echo "alert(&#39;用户名或密码错误,请重试!&#39;);location=&#39;index.php&#39;;";
}
?>
运行得到
Bingle!
提交既能判断验证码是否正确,又能查询到信息。
希望我的解答能帮到你,如果还有什么疑问可以继续帮你解答。
Love code,love life.