将数据插入数据库表问题

时间:2016-06-02 12:34:18

标签: php jquery mysql ajax

我想要注册表格。但是我无法将数据插入到我的数据库表格中#34; yeni" 并得到"错误...... !!"。我真的需要解决这个问题,伙计们请帮助我。

http://i.stack.imgur.com/SoCNK.png

registration.js

$(document).ready(function() {
  $("#register").click(function() {
    var name = $("#name").val();
    var tc = $("#tc").val();
    var tel = $("#tel").val();
    var password = $("#password").val();
    var cpassword = $("#cpassword").val();

    if (name == '' || tc == '' || tel == '' || password == '' || cpassword == '') {
      alert("Please fill all fields...!!!!!!");
    }
    else if ((password.length) < 8) {
      alert("Password should atleast 8 character in length...!!!!!!");
    }
    else if (!(password).match(cpassword)) {
      alert("Your passwords don't match. Try again?");
    }
    else {
      $.post("sign.php", {
        name1: name,
        tc1:tc,
        tel1: tel,
        password1: password
      }, function(data) {
        if (data == 'You have Successfully Registered.....') {
          $("form")[0].reset();
        }
        alert(data);
      });
    }
  });
});

sign.php

<?php
  $connection = @mysql_connect("localhost", "root", ""); 
  $db = mysql_select_db("babo", $connection); 

  $name = $_POST['name1']; // Fetching Values from URL.
  $tc = $_POST['tc1'];
  $tel = $_POST['tel1'];
  $password = sha1($_POST['password1']);

  $query = mysql_query("insert into yeni(adi, tc_no, password, tel) values ('$name', '$tc', '$password', '$tel')"); 

  if($query) {
    echo "You have Successfully Registered.....";
  } else {
    echo "Error....!!";
  }

  mysql_close ($connection);
?>

1 个答案:

答案 0 :(得分:1)

  1. 已经建议使用mysqli_函数支持mysql_ functions
  2. 您应该使用prepered statements
  3. 为了获得一个更好的起点,实际上错误地将echo "Error....!!";替换为echo mysqli_error($connection);