0

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
16
  • Please post the code you use to execute the query, and the full table definition. Commented Oct 29, 2011 at 7:21
  • Is the semicolon within the SQL string supposed to be there? From what I know MySQL does not need to end with a semicolon. Commented Oct 29, 2011 at 7:28
  • @Seralize It makes no difference Commented Oct 29, 2011 at 7:29
  • @Serialize: You are right, the semicolon shouldn't be there. From the PHP manual The query string should not end with a semicolon. However I think MySQL just ignores it, so I don't think it can explain the error. Commented Oct 29, 2011 at 7:30
  • 2
    So build up the script from the "bare command which works" unto the "script you have that doesn't work". Test after every logical block. Somewhere it will stop working. Commented Oct 29, 2011 at 8:15

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I found the problem, the service I was using got changed to return XML where it usually just returned an integer, this caused me to try and insert XML into my BIGINT field, which is not possible. So in the end the problem was caused by an updated service that didn't notify clients about changes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.