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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效