php mysql查询没有正确执行

时间:2011-10-29 07:16:26

标签: php mysql insert

我的sql脚本有一个奇怪的问题。

我有一个字符串

$query = "INSERT into sms_replyid (eventid, bus_id, cell_num, sms_message) 
          VALUES ('93361357', '2162', '27761144734', 'Hoekom');";

但是当我执行该字符串时,它会将其插入到表中但是偶数保持为0,如果我在cmd中运行那个确切的命令它是否完美?

为什么没有插入所有值的任何想法?

编辑完整代码

<?php session_start();

$link = mysql_connect("localhost", "username", "password"); //removed u and p for posting

if (!$link)

    die("Couldn't connect to MySQL");

mysql_select_db("db", $link) //removed db name for posting

or die ("Couldn't open smss:" . mysql_error());
$id = $_SESSION['id'];

$message = $_REQUEST['promo_message'];
$timeToSend = $_REQUEST['timeToSend'];
$dateToSend = $_REQUEST['dateToSend'];





    if(isset($_REQUEST['input_cell']))
    {
        $receiver = $_REQUEST['input_cell'];
        if($receiver != '')
        {
            $response_string = sendSMSPortalSchedule($message, $receiver, $sender_id, $dateToSend, $timeToSend);
            $response_string = str_replace ( "True" , "", $response_string );
//This does not work right, all gets added perfectly yet eventid stays 0 enven while all the others get the right values
        $query1 = "INSERT into sms_replyid (eventid, bus_id, cell_num, sms_message) VALUES ('$response_string', '$id', '$receiver', '$message');";

        mysql_query($query1);
        echo mysql_error();
        }
    }
    if(isset($_REQUEST['single_cell']))
    {
        $receiver = $_REQUEST['single_cell'];
        if($receiver != 'none')
        {
        $response_string = sendSMSPortalSchedule($message, $receiver, $sender_id, $dateToSend, $timeToSend);
        $response_string = str_replace ( "True" , "", $response_string );
        $query2 = "INSERT into sms_replyid (eventid, bus_id, cell_num, sms_message) VALUES ('$response_string', '$id', '$receiver', '$message');";
//This does not work right, all gets added perfectly yet eventid stays 0 enven while all the others get the right values
        mysql_query($query2);
        echo mysql_error();

        }

    }

    if(isset($_REQUEST['sento_group']))
    {
            $array = $_REQUEST['sento_group'];
        foreach($array as $receiver)
        {
            if($receiver != 'none')
            {
                $query = 'SELECT cell_number FROM cell_groups WHERE group_id ="'.$receiver.'"';
                $result2 = mysql_query($query) or die('Fail');

                while($row=mysql_fetch_array($result2))
                {
                $response_string = sendSMSPortalSchedule($message, $row['cell_number'], $sender_id, $dateToSend, $timeToSend);
                $response_string = str_replace ( "True" , "", $response_string );
                $to = $row['cell_number'];
                $query3 = "INSERT into sms_replyid (eventid, bus_id, cell_num, sms_message) VALUES ('$response_string', '$id', '$to', '$message');";
//This does not work right, all gets added perfectly yet eventid stays 0 enven while all the others get the right values
                        mysql_query($query3);
                echo mysql_error();
            }
            }
        }
    }
}

这是表格

id = INT
eventid = BIGINT(20)
bus_id = INT
cell_num = VARCHAR
sms_message = VARCHAR

2 个答案:

答案 0 :(得分:1)

SQL命令本身是正确的。问题必定在其他地方。

首先,您确定参数的值是否正确?尝试在变量插值后输出查询以查看它是否正确:

$query1 = "INSERT into sms_replyid (eventid, bus_id, cell_num, sms_message) VALUES ('$response_string', '$id', '$receiver', '$message')";
echo $query1;

我注意到你在多个地方都有INSERT。确保所有按预期工作。请记住,您认为正在执行的那个可能与实际正在执行的那个不同。

答案 1 :(得分:1)

我发现了问题,我使用的服务被更改为返回XML,它通常只返回一个整数,这导致我尝试将XML插入到我的BIGINT字段中,这是不可能的。因此,最终问题是由更新的服务引起的,该服务未通知客户有关更改的信息。