回应sql查询添加一个新行

When I echo my sql query it displays

the volunteer id is 312INSERT INTO volunteer_events (event_id, volunteer_id) VALUES ('91  
', '312')

It adds a new line after '91 rather than having it all in one line. I was wondering what I'm doing which causes it to add a new line.

public function addUserToEvent($event,$volunteer)
{
    $event_id = $event;
    echo "the event id is ". $event_id;
    $volunteer_id = $volunteer;
    echo "the volunteer id is ". $volunteer_id;
    $sql = "INSERT INTO volunteer_events (event_id, volunteer_id) VALUES ('$event_id', '$volunteer_id')";
    echo $sql;
    return mysql_query($sql);
}

I'm calling addUserToEvent here

if(isset($_POST["events"])){
    $eventIds = $_POST["events"];
    $N = count($eventIds);
    for($i=0; $i < $N; $i++) {
      echo "</br>";
      echo "The events IDs are";
      echo "</br>";
      echo($eid = $eventIds[$i]);

     $sql = "SELECT distinct v.id 
            FROM volunteers v
            WHERE v.first_name = '$fname'
            AND v.last_name = '$lname'
            AND v.email = '$email'";

     $results = $db->q($sql);
     if($row = $results->getAssoc()) 
      {
            $vID = $row['id'];
            echo "the vid is ". $vID;
      }
      echo "</br>";
      echo " the eid is blah ".$eid;
     echo $db->addUserToEvent($eid, $vID);
    }


}

Very simple to fix, just cast to int.

public function addUserToEvent($event,$volunteer)
{
    $event = (int) $event;
    $volunteer = (int) $volunteer;
    $event_id = $event;
    echo "the event id is ". $event_id;
    [...]

What I am thinking is that the datatype of field volunteer.id is a varchar where it should be an INT. Casting your variables is always good practice.