douguan3470 2012-03-18 21:39
浏览 49
已采纳

我的php脚本只读取mysql的第一行,并没有检查其余的行是否匹配

I'm trying to write a script for users to register to a club, and it does all the validation stuff properly and works great until it gets to the part where its supposed to check for duplicates. I'm not sure what is going wrong. HELP PLEASE!!! Thank you in Advance,

  <?php 
  mysql_connect ("sqlhost", "username", "password") or die(mysql_error());

  mysql_select_db ("databasename") or die(mysql_error());

  $errormsgdb = "";
  $errordb = "Sorry but that ";
  $error1db = "Name";
  $error2db = "email";
  $error3db = "mobile number";
  $errordbe = " is already registered";
  $pass1db = "No Matching Name";
  $pass2db = "No Matching Email";
  $pass3db = "No Matching Mobile";
  $errorcount = 0;
  $qResult = mysql_query ("SELECT * FROM table");
  $nRows = mysql_num_rows($qResult);
  for ($i=1; $i< $nRows+1; $i++){

$result = mysql_query("SELECT id,fname,lname,dob,email,mobile,agree,code,joindate FROM table WHERE fname = '$ffname");
if ($result > 0) {
$errorcount = $errorcount++;
$passdb = 0;
$errormsgdb = $error1db;
echo "<div class=\"box red\">$errordb $errormsgdb
} else {
$pass = 1;
$errormsgdb = $pass1db; 
echo "<div class=\"box green\">$errormsgdb</div><br />";
}



  //--------------- Check if DB checks returned errors ------------------------------------>
        if($errorcount <= 0){
        $dobp = $_REQUEST['day'].'/'.$_REQUEST['month'].'/'.$_REQUEST['year'];
        $dob = $_REQUEST['year'].$_REQUEST['month'].$_REQUEST['day'];
        //header('Location: thankyou.php?ffname='.$ffname.'&flname='.$flname.'&dob='.$dob.'&femail='.$femail.'&fmobile='.$fmobile.'&agree='.$agree.'&code='.$code.'&dobp='.$dobp);
        echo "<div class='box green'>Form completed! Error Count = $errorcount</div>";
        } else {
        echo "<div class='box red'>There was an Error! Error Count = $errorcount</div>";
            }
  }
     ?>
  • 写回答

3条回答 默认 最新

  • dousong9729 2012-03-18 21:47
    关注

    There are quite a few things that don't make sense in your script, the multiple queries for one ! why not just query for the data and see if you get a match - instead of looping each user and checking it ?? ... but I think your main problem is

    $errorcount = " ";
    

    then you do

    $errorcount = $errorcount++;
    

    this will NOT work ... you created $errorcount as a string so incrementing it won't work. You should initialise it as a number :

    $errorcount = 0;
    

    then to increment :

    $errorcount++;
    

    Example of it not working and then working here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP