Query is not inserting data into db
<p>I am at a loss why my query is not inserting values into db. Even if I do <code>echo $query</code> or <code>var_dump($query)</code> there is nothing printed at all. All values are being passed successfully just not being inserted. I am getting <code>Could not connect</code> but I do not know why. All connections are established and as a test I took this code and ran it on its own with dummy data and it inserted the data fine. I can only think it has something to do with the <code>$response_array</code>. Where am I going wrong?</p>

<pre><code>&lt;?php require_once('Connections/sample.php'); ?&gt;
&lt;?php

session_start();

$new = 1;
$activity = 'General Contact Enquiry';
$mobile = 'Submitted from mobile';
$name = mysql_real_escape_string($_POST['GC_name']);
$department = mysql_real_escape_string($_POST['GC_department']);
$message = mysql_real_escape_string($_POST['GC_message']);
$email = mysql_real_escape_string($_POST['GC_email']);
$company = mysql_real_escape_string($_POST['GC_company']);
$position = mysql_real_escape_string($_POST['GC_position']);

//response array with status code and message
$response_array = array();

//validate the post form

//check the name field
if(empty($name)){

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'Name cannot be blank';

//check the name field
} elseif(empty($company)) {

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'You must enter a company name';

//check the position field
}elseif(empty($position)) {

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'You must enter a position';

//check the email field
} elseif(empty($email)) {

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'You must enter a valid email address';

//check the dept field
}elseif($department=="Choose Department") {

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'You must select a department';

//check the message field
}elseif(empty($message)) {

    //set the response
    $response_array['status'] = 'error';
    $response_array['message'] = 'You must enter a message';

//check the dept field
}
else {

    //set the response
    $response_array['status'] = 'success';
    $response_array['message'] = 'Your enquiry has been sent succesfully';
    $flag=1;
 }

//send the response back
echo json_encode($response_array);

if($flag == 1) {

    mysql_select_db($database_sample, $sample);
    $query = 'INSERT INTO feedback (company, department, name,  email, position, feedback, date, new) VALUES (\''.$company.'\', \''.$department.'\', \''.$name.'\', \''.$email.'\', \''.$position.'\', \''.$message.'\', NOW() , \''.$new.'\')';
    mysql_query($query) or die("Could not connect");
    }


?&gt;
</code></pre>
