php注册表单,在phpmyadmin中添加更多列

时间:2017-03-18 16:59:33

标签: php mysql registration

我做了一个简单的注册表单,但是当我在phpmyadmin中添加更多列时,我无法注册用户,因为服务器错误导致注册失败。请稍后再试。 感谢帮助。     

    if($password==$cpassword)
    {
      $query = "select * from user where username='$username'";
      $query_run = mysqli_query($con,$query);
      if($query_run)
      {
        if(mysqli_num_rows($query_run)>0)
        {
          echo '<script type="text/javascript">alert("This Username Already exists.. Please try another username!")</script>';
        }
        else
        {
          $query = "insert into user values('$username','$password')";
          $query_run = mysqli_query($con,$query);
          if($query_run)
          {
            $_SESSION['username'] = $username;
            $_SESSION['password'] = $password;
            // header( "Location: profile.php");
            echo '<script type="text/javascript">alert("User Registered.. Welcome")</script>';
          }
          else
          {
            echo '<p class="bg-danger msg-block">Registration Unsuccessful due to server error. Please try later</p>';
          }
        }
      }
      else
      {
        echo '<script type="text/javascript">alert("DB error")</script>';
      }
    }
    else
    {
      echo '<script type="text/javascript">alert("Password and Confirm Password do not match")</script>';
    }

  }
  else
  {
  }
?>

我试图添加不同的列,没有任何作用,我想我只需要更改$ query函数或者其他东西。例如,当我只有用户名和密码列但是当我添加user_id或者创建用户的日期。这个表格有什么问题?

2 个答案:

答案 0 :(得分:0)

我认为问题是当您插入列user_id时忘记将其键设置为主键并将其设置为自动增量,我在您的查询中假设该表只有用户名和密码字段,所以那里没有进程或插入user_id,因此您的查询返回错误。

答案 1 :(得分:0)

好吧,我发现问题是什么,这么简单,我只需要改变:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let newLocation = locations.last

//check accuracy and timestamp of location to make sure its not a cached/old location (if you don't care about accuracy or time, you can remove this check)
    let timeDiff = newLocation?.timestamp.timeIntervalSinceNow

    if timeDiff < 5.0 && (newLocation?.horizontalAccuracy)!<=self.accuracyNeeded{

        //stop updating location
        self.locationManager.stopUpdatingLocation()

        //set currentUserLocation
        self.myLocation=newLocation?.coordinate


        //call function to get weather

        //remove delegate
        self.locationManager.delegate = nil

    }

}

由于id列的类型为AUTO_INCREMENT,因此MySQL将根据顺序确定下一个可用数字的值。我读到这个: 学习php mysql和javascript robin nixon。 不管怎样,谢谢。