duan33360 2018-01-03 22:42
浏览 46
已采纳

MySQL注册连接错误

I have a problem with a signup option that I’ve created on my website. For my signup option, I have followed this tutorial exactly: https://code.tutsplus.com/tutorials/building-a-sleek-ajax-email-signup-form--net-13645

It worked like a charm on my test website, but now that I’ve moved everything to another server, I get two different types of error messages.

The first one: Error1

The error concerns the following line in my javascript file:

var responseData = jQuery.parseJSON(data),

This is what Safari, Firefox and Opera are telling me. And then Chrome is also reporting this error: Error2

Is this maybe because mysql functions have been removed in PHP7? My new server uses PHP 5.6 though… My PHP looks like this at the moment:

    <?php
if(isset($_GET['action'])&& $_GET['action'] == 'signup'){
  mysql_connect('localhost:3306','db_username','db_password');
  mysql_select_db('db_name');

  //sanitize data
  $email = mysql_real_escape_string($_POST['signup-email']);

  //validate email address - check if input was empty
  if(empty($email)){
    $status = "error";
    $message = "You did not enter an email address";
  }
  else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){ //validate email address - check if is a valid email address
    $status = "error";
    $message = "Invalid email address";
  }
  else {
    $existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
    if(mysql_num_rows($existingSignup) < 1){

  $date = date('Y-m-d');
  $time = date('H:i:s');

  $insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time) VALUES ('$email','$date','$time')");
  if($insertSignup){
    $status = "success";
    $message = "You have been signed up";
  }
  else {
    $status = "error";
    $message = "Ooops, there has been a technical error";
  }
}
else {
  $status = "error";
  $message = "This email address has already been registered";
}
  }

      //return json response
      $data = array(
        'status' => $status,
        'message' => $message
      );

      echo json_encode($data);

      exit;
    }
    ?>

Would I have to rewrite this with the new mysqli_connect()? How would I have to do that? But then I’m still left with first problem… Does anyone have an idea how I can solve these two problems? Thank you very much!

  • 写回答

1条回答 默认 最新

  • doudi8231 2018-01-03 23:04
    关注

    Option 1

    Probably your server has newer version of PHP (>= 7.0.0). The MySQL extension was deprecated in PHP5.5.0 and removed in 7.0.0

    The reason mysql_* functions were removed is that they were implemented in the early 2.0 version of PHP, which means that they are over 15 years old. This library limits MySQL functionality and has become very hard to maintain.

    If you are a beginner I would recommend looking for a MySQLi or PDO_MySQL library tutorial, or you can port the code yourself if you have a little bit more experience.

    Option 2

    Another possible cause is because the MySQL extension is disabled in your php.ini file. To see more info about your current PHP configuration create and open a new PHP file containing the following:

    <?php phpinfo(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)