douyao3895 2018-04-03 07:46
浏览 73

mysqli_query和错误查询问题[重复]

I am getting warning message

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\gurukul\user\viewegister_user.php on line 24

Warning: mysqli_error() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\gurukul\user\viewegister_user.php on line 24

Below is code :

<?php             
    $fname = '';
    $lname = '';
    $email = ''; 
    $conn = '';
        if(isset($_POST ['register']))
        {
            // Assign local variables to form data
            $fname = trim($_POST['fname']);
            $lname = trim($_POST['lname']);
            $email = trim($_POST['email']);

            $fname = stripcslashes($fname) ;                                      
            $lname = stripcslashes($lname);
            $email = stripcslashes($email);

            if(!empty($fname and $lname and $email)){
                            // Connect to db


                // Validate if the email account already exists
                $query = "SELECT email FROM tbl_users  WHERE email ='$email'";
                //$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
                $result = mysqli_query($conn, $query) or die(mysqli_error($conn));

                $count = mysql_num_rows($result);
            /*
               echo $row[0];
               echo $count;
               echo $fname;
               echo $email;           
               echo $lname; 
              */
            // Generate random 32 character hash and assign it to a local variable.
            // Example output: f4552671f8909587cf485ea990207f3b
                $hash = md5( rand(0,1000) );
                $password = rand(1000,5000); // Generate random number between 1000 and 5000 and assign it to a local variable.    // Example output: 4568
                $md5_password  = md5($password) ;

            if (empty($row = mysqli_fetch_array($result))) 
               {              

                    $to      = $email; // Send email to our user
                    $subject = 'Signup | Verification'; // Give the email a subject 
                    $message = '

                                Thanks for signing up!
                                Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.

                                ------------------------
                                    Username: '.$email.'
                                    Temporary Password: '.$password.'
                                ------------------------

                                Please click this link to activate your account:
                               http://localhost/gurukul/user/verify.php?email='.$email.'&hash='.$hash.'

                               ';  // Activation link -Concatenate email and md5 hash - direct to verify.php to validate the link
                                 // Our message above including the link

                                $headers = 'From:noreply@yourwebsite.com' . "
"; // Set from headers
                                $usertype = "Stu_Account";
                        if(mail($to, $subject, $message, $headers)){// Send our email  --- and if email sent successfully then insert data into db
                         // Insert new user data into users table
                         $query = "INSERT INTO tbl_users(f_name,l_name,email,hash,temp_password,user_type) VALUES ('$fname','$lname','$email','$hash','$md5_password','$usertype') ";
                         $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
                         mysqli_close($conn);    

               //          echo $md5_password;
               //          echo 'check mail';                                                  
               //          echo $password;
                         ?>
                             <script type="text/javascript"> 
                              //   history.back(); 
                                 window.location.replace("index.php");
                                 alert("Your account is successfully created! 
 An email is sent on your account.  Please check your email shortly to activate your account. ");                             
                            </script> 

                         <?php    

                        }  else{
                            ?>
                             <script type="text/javascript"> 
                                 history.back();
                                 alert("Email Could Not be Sent. 

Your Account is Not Created, Try Again Shortly. 
 
Please Contact Administator if the Issue Persists. ");                             
                             </script>    
                            <?php
                        }                        
                }else{
                 // The Email Account is Already Registered';
                 ?>
                      <script type="text/javascript"> 
                        history.back(); 
                        alert("This email id is already registered.

 Please go to home page to login or create a new account with another email id.");                             
                    </script> 
                  <?php       

                }                

            }else{
                  ?>
                      <script type="text/javascript"> 
                        history.back(); 
                        alert("Some data is missing, please enter all the details..");                             
                    </script> 
                  <?php 
            }

        }
  ?>
</div>
  • 写回答

1条回答 默认 最新

  • doulou9927 2018-04-03 07:49
    关注

    You need to define: $conn before

    $conn = mysqli_connect("localhost", "my_user", "my_password", "db");

    评论

报告相同问题?

悬赏问题

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