douxi9245 2011-10-29 07:16
浏览 20
已采纳

php mysql查询没有正确执行

I have a weird problem with my sql script.

I have a string

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

But when I execute that string it inserts it to the table but eventid stays 0, if I run that exact command in cmd it works perfectly?

Any ideas why this is not inserting all the values?

Edit Full code

<?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();
            }
            }
        }
    }
}

This is the table

id = INT
eventid = BIGINT(20)
bus_id = INT
cell_num = VARCHAR
sms_message = VARCHAR
  • 写回答

2条回答 默认 最新

  • duanfu5239 2011-10-29 07:19
    关注

    The SQL command itself is correct. The problem must be elsewhere.

    Firstly, are you sure that the values of your parameters are correct? Try outputting the query after variable interpolation to see if it is correct:

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

    Seondly I notice that in you have INSERTs in multiple places. Make sure all of them work as expected. Remember that the one you think is executing may be different from the one that is actually executing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面