0

I'm having a huge issue with this database. It connects correctly and with the information from the form's $_POST queries that are being inserted into the table company_info within the correct fields.

Now, I have no idea what I'm doing wrong here, but I keep getting the die error of

"Error querying database".

The database version is: phpMyAdmin 2.6.4-pl3

MySQL: 5.0

Any ideas? I can provide you the rest of the code if needed.

$dbc = mysql_connect('db390590179.db.1and1.com', 'dbo390590179', '*********')
or die('Error connecting to MySQL server.');

mysql_select_db("db390590179", $dbc);


$query = "INSERT INTO company_info (company_name, company_phone,  company_contact, company_address, " .
"company_city, company_state, company_zip, " .
"state_living, vehicles, position, " .
"experience, training, hazmat, " .
"require_hazmat, load_nyc, take_truck_home, " .
"have_rider, have_pet, choose_route, " .
"fuel, cash_advance, days_before_home, " .
"log_system, slip_seat, pre_pass, " .
"ez_pass, health_insurance, retirement_plan, " .
"payment_plan, calculate_pay, freight, " .
"loads, home_on_time, idle_time, " .
"equipment_condition, canada)" .

"VALUES ('$company_name', $company_phone', '$company_contact', '$company_address', '$company_city', " .
"'$company_state', '$company_zip', " .
"'$state_living', '$vehicles', '$position', " .
"'$experience', '$training', '$hazmat', " .
"'$require_hazmat', '$load_nyc', '$take_truck_home', " .
"'$have_rider', '$have_pet', '$choose_route', " .
"'$fuel', '$cash_advance', '$days_before_home', " .
"'$log_system', '$slip_seat', '$pre_pass', " .
"'$ez_pass', '$health_insurance', '$retirement_plan', " .
"'$payment_plan', '$calculate_pay', '$freight', " .
"'$loads', '$home_on_time', '$idle_time', " .
"'$equipment_condition', '$canada')";

$result = mysql_query($query, $dbc)
or die('Error querying database.');

mysql_close($dbc);

4 Answers 4

1

I think it's because it's missing a quote before the variable $company_phone in your INSERT statement.

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

Comments

0

just combine the different values within a single quote.

E.g., "'$company_state , $company_zip,' " ."'$state_living , $vehicles, $position, '" ."'$experience, $training, $hazmat, '" ....

this will work perfectly and also include the missing quote in the begining of the *$company_phone* has to be included.

Comments

0

You can remove double quote from each line and combine them. I have removed syntax errors. You can assure that result is getting or not. Try this code.

$dbc = mysql_connect('db390590179.db.1and1.com', 'dbo390590179', '*********')
        or die('Error connecting to MySQL server.');

mysql_select_db("db390590179", $dbc);


$query = "INSERT INTO company_info (company_name, company_phone,  company_contact, company_address,
        company_city, company_state, company_zip,
        state_living, vehicles, position,
       experience, training, hazmat,
       require_hazmat, load_nyc, take_truck_home,
        have_rider, have_pet, choose_route,
       fuel, cash_advance, days_before_home,
        log_system, slip_seat, pre_pass,
        ez_pass, health_insurance, retirement_plan,
        payment_plan, calculate_pay, freight,
        loads, home_on_time, idle_time,
        equipment_condition, canada)

        VALUES ('$company_name', '$company_phone', '$company_contact', '$company_address', '$company_city',
       '$company_state', '$company_zip',
        '$state_living', '$vehicles', '$position',
        '$experience', '$training', '$hazmat', 
        '$require_hazmat', '$load_nyc', '$take_truck_home',
        '$have_rider', '$have_pet', '$choose_route',
        '$fuel', '$cash_advance', '$days_before_home',
        '$log_system', '$slip_seat', '$pre_pass',
        '$ez_pass', '$health_insurance', '$retirement_plan',
        '$payment_plan', '$calculate_pay', '$freight',
        '$loads', '$home_on_time', '$idle_time',
        '$equipment_condition', '$canada')";

$result = mysql_query($query, $dbc)
        or die('Error querying database.');

mysql_close($dbc);

Comments

0
for (int i = 0; i < CheckBoxList1.Items.Count - 1; i++)
{
  String str = "";
  if (CheckBoxList1.Items[i].Selected)
  {
    str = CheckBoxList1.Items[i].Text;
    con.Open();
    string sql =
      "Insert into dbtable(Category,BookTitle,Feature,SubCategory)values('" +
      DDLCategory.SelectedItem.Text + "','" + TxtBooktitle.Text + "','" +
      CheckBoxList1.Items[i].Text + "','" + DDLSubcategory.SelectedItem.Text +
      "')";
    SqlCommand cmd = new SqlCommand(sql, con);
  }
}

Just use DEBUGGER and see how things are working and you should be able to resolve such issues easily.

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.