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条)

报告相同问题?

悬赏问题

  • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
  • ¥15 arduino上连sim900a实现连接mqtt服务器
  • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
  • ¥66 关于人体营养与饮食规划的线性规划模型
  • ¥15 基于深度学习的快递面单识别系统
  • ¥15 Multisim仿真设计地铁到站提醒电路
  • ¥15 怎么用一个500W电源给5台60W的电脑供电
  • ¥15 请推荐一个轻量级规则引擎,配合流程引擎使用,规则引擎负责判断出符合规则的流程引擎模板id
  • ¥15 Excel表只有年月怎么计算年龄