我只是想制作一个简单的注册表格,当空白空白时,我点击按钮,我可以看到"请填写所有字段"但是当我填空并点击提交按钮时没有任何反应。无法看到"表格已成功提交"任何插入我的桌子" hastalar" .Pls帮助我。
http://www.eksiduyuru.com/files/1464/1464794851_1.jpg" undefined"
http://www.eksiduyuru.com/files/1464/1464794851.jpg" hastalar table"
$(document).ready(function(){
$("#submit").click(function(){
var name = $("#name").val();
var tc = $("#tc").val();
var password = $("#password").val();
var contact = $("#contact").val();
var dataString = 'name1='+ name + '&tc1='+ tc + '&password1='+ password + '&contact1='+ contact;
if(name==''||email==' '||password==''||contact=='')
{
alert("Please Fill All Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "ajaxsign.php",
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});
<?php include ("includes/db.php"); ?>
<?php
if(isset($_POST["submit"])){
$name2=$_POST['name1'];
$tc2=$_POST['tc1'];
$password2=$_POST['password1'];
$contact2=$_POST['contact1']; }
//Insert query
$query =mysql_query("insert into hastalar(adi, tc_no, password, tel) values ('$name2', '$tc2', '$password2','$contact2')");
if (!empty($name2) && !empty($tc2) && !empty($password2) && !empty($contact2) )
{
echo "Form Submitted Succesfully";
}
if(isset($connection)){
mysql_close($connection);
}
?>
$connection=@mysql_connect("localhost","root","");
if(!$connection){
die("Veritabanı bağlantı hatası:".mysql_error());
}
$db=mysql_select_db("proje",$connection);
if(!$db){
die("Veritabanı tablo seçim hatası:".mysql_error());
}
答案 0 :(得分:0)
script.js:语法错误。 将vvar dataString更改为var dataString
.. 确定编辑了我的答案。
$(document).ready(function(){
$("#submit").click(function(){
var name = $("#name").val(),
tc = $("#tc").val(),
password = $("#password").val(),
contact = $("#contact").val();
if(name==''||email==' '||password==''||contact=='') {
alert("Please Fill All Fields");
} else {
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "ajaxsign.php",
data: {'name1':name,'tc1':tc,'password1':password,'contact1':contact},
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});