ajax无法将数据字符串传递给php

时间:2012-11-27 01:44:28

标签: javascript php ajax database string

我无法在我的php脚本上收到数据值,ajax成功触发,但发送时数据库中的数据没有更改。

        $.ajax({
        type: "POST",
        url: "database/clientpanel/agent_panel/notiffolder/notifedit.php",
        data: {
        email: email,
        number: number,
        emailon: emailon,
        texton: texton,
        email_delay: emaildel,
        ext_delay: textdel,
        timezone1: zone1,
        timezone2: zone2
        },
        cache: false,
        success: function(html){
            $("#upnotif").show();
            $("#errnotif").hide();
            $("#errnotif1").hide();
            $("#errnotif2").hide();
        }
    });

PHP

<?php
session_start();
include("../../../dbinfo.inc.php");

$query=" select * from tele_panel_notification where client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$client = $row['client'];

if($client == ""){
$query = "insert into tele_panel_notification set
emailon = '".$mysqli->real_escape_string($_POST['emailon'])."',
texton = '".$mysqli->real_escape_string($_POST['texton'])."',
timezone = '".$mysqli->real_escape_string($_POST['timezone'])."',
timezone2 = '".$mysqli->real_escape_string($_POST['timezone2'])."',
email = '".$mysqli->real_escape_string($_POST['email'])."',
email_delay = '".$mysqli->real_escape_string($_POST['email_delay'])."',
text_delay = '".$mysqli->real_escape_string($_POST['text_delay'])."',
number = '".$mysqli->real_escape_string($_POST['number'])."',
client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";

    //execute the query
    if( $mysqli->query($query) ) {
        //if saving success
        echo "true";
    }else{
        //if unable to create new record
        printf("Errormessage: %s\n", $mysqli->error);
    }
}
else{
$query = "UPDATE tele_panel_note SET 
emailon = '".$mysqli->real_escape_string($_POST['emailon'])."',
texton = '".$mysqli->real_escape_string($_POST['texton'])."',
timezone = '".$mysqli->real_escape_string($_POST['timezone'])."',
timezone2 = '".$mysqli->real_escape_string($_POST['timezone2'])."',
email = '".$mysqli->real_escape_string($_POST['email'])."',
email_delay = '".$mysqli->real_escape_string($_POST['email_delay'])."',
text_delay = '".$mysqli->real_escape_string($_POST['text_delay'])."',
number = '".$mysqli->real_escape_string($_POST['number'])."'
where client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";

    //execute the query
    if( $mysqli->query($query) ) {
        //if saving success
        echo "true";
    }else{
        //if unable to create new record
        printf("Errormessage: %s\n", $mysqli->error);
    }
}   

    //close database connection
$mysqli->close();

?>

1 个答案:

答案 0 :(得分:2)

看看你的PHP部分,

   $result = $mysqli->query($query);
   $row = $result->fetch_assoc();
   $client = $row['client'];

   if($client == ""){

如果您想知道该行是否已存在,则应直接验证您的行:

   $result = $mysqli->query($query);
   $row = $result->fetch_assoc();
   //$client = $row['client'];

   if(!$row){

然后你的客户变量就没用了。