Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:22:52+00:00 2026-05-25T19:22:52+00:00

I am at a loss why my query is not inserting values into db.

  • 0

I am at a loss why my query is not inserting values into db. Even if I do echo $query or var_dump($query) there is nothing printed at all. All values are being passed successfully just not being inserted. I am getting Could not connect 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 $response_array. Where am I going wrong?

<?php require_once('Connections/sample.php'); ?>
<?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");
    }


?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:22:53+00:00Added an answer on May 25, 2026 at 7:22 pm

    May be you need to verify the $query content.

    Try this way,

    $query = "INSERT INTO `feedback` (`company`, `department`, `name`,  `email`,
              `position`,`feedback`, `date`, `new`) VALUES 
              ('$company','$department','$name','$email','$position',
              '$message',NOW(),'$new')";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can query the database to return only the elements
Simple php/mysql INSERT such as mysql_query(INSERT INTO dispatch VALUES('1234','$name','$address')); intermittently fails. I've set it
I've started using HTML5 and WebSQL, and I quickly ran into a problem: all
I am at a loss with this one. First of all, something strange: every
Apologies if this has been asked before but is there any way, at all,
Not sure how far a sql query can go with if/else statements. I have
I'm at a loss for where to get the best information about the meaning,
I'm at a loss, I can't see the reason something as simple as this
The fundamental equation of weight loss/gain is: weight_change = convert_to_weight_diff(calories_consumed - calories_burnt); I'm going
How do type casting happen without loss of data inside the compiler? For example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.