PHP没有插入数据

时间:2016-07-03 01:12:57

标签: php database mysqli

我在本地服务器上运行它并且它工作得很好,但是当我将它上传到我的网络托管时,它就停止了工作。 基本上当我提交表单时,浏览器只是继续加载,当我检查数据库时没有插入数据。 我检查了我的数据库连接,我能够连接它,但无法从中获取数据。

这是我的php:

<?php
$servername   = "localhost";
$username     = "itclubac_root";
$password     = "*******";
$dbname       = "itclubac_itclub";


$tnp          = 0;
$name         = $_POST['name'];
$email        = $_POST['email'];
$gender       = $_POST['gender'];
$phone        = $_POST['phone'];
$id           = $_POST['id'];
$section      = $_POST['section'];
$skills       = $_POST['skills'];
$interests    = $_POST['interests'];
$expectations = $_POST['expectations'];
$tnp          = $_POST['tnp'];
$ip           = $_SERVER['REMOTE_ADDR'];

if ( $tnp == 0 ) { 
  header('Location: ../../get_involved.php'); 
} else {    
  // Create connection
  $con = new mysqli($servername, $username, $password, $dbname);

  // Check connection
  if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
  }
  $query = mysqli_query($con, "SELECT * FROM member_registration WHERE email = '".$email. "'"); 
  if ( mysqli_num_rows($query) > 0 ) {
    header('Location: ../../get_involved.php?status=exist');
  } else {    
    $query = mysqli_query($con, "SELECT * FROM member_registration WHERE college_id = '".$id. "'"); 
    if ( mysqli_num_rows( $query) > 0 ) { 
      header('Location: ../../get_involved.php?status=exist'); 
    } else { 
      $sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', '$skills', '$interests', '$expectations', '$ip')";
      if ($con->query($sql) === TRUE) {
        header('Location: ../../get_involved.php?status=success'); 
      } 
    } 
  } 
} 
$con->close();
?>

修改

这是网站:Form Page http://itclub.acc.edu.bd/get_involved.php如果您在此处注册,该页面将继续加载。但是,如果您尝试直接访问registration.php,它会将您发送到我所说的表单页面页面。当我在本地测试它时,它工作得很好,但在上传到主机后,这个问题正在发生。

1 个答案:

答案 0 :(得分:0)

我尝试对您的代码进行排序,但错误可能与您的查询有关,

$sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', $'skills', '$interests', '$expectations', '$ip')";

您是否注意到该部分的$'skills'部分?将代码更改为,

$sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', '$skills', '$interests', '$expectations', '$ip')";

也许有帮助。