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

  • Home
  • SEARCH
  • 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 9203951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:35:27+00:00 2026-06-17T23:35:27+00:00

Can anyone tell me what is wrong with my Query? I have two tables

  • 0

Can anyone tell me what is wrong with my Query?
I have two tables event and customer, I want to select customer id from customer table and insert it in the customer_id Column in the event table. this is only where the login id in the customers table is the same as the logged in user id

$insEvent_sql = "INSERT INTO event(customer_id, videography_package, event_type, event_shortdesc, event_vanue, event_start) 
VALUES(customer-id,'".$safe_videography_package."', '".$safe_event_type."', '".$safe_event_shortdesc."','".$safe_event_vanue."',  '".$event_date."') SELECT customer_id  FROM 'customer' WHERE login_id = ".$_SESSION['SESS_LOGIN_ID'].";";
  • 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-06-17T23:35:29+00:00Added an answer on June 17, 2026 at 11:35 pm

    You cannot INSERT a row followed by a SELECT. A work around is to add your row to the SELECT:

    $insEvent_sql = "INSERT INTO event 
                (customer_id, 
                 videography_package, 
                 event_type, 
                 event_shortdesc, 
                 event_vanue, 
                 event_start) 
    SELECT 'customer-id'                        AS customer_id, 
           '" . $safe_videography_package . "'  AS videography_package, 
           '" . $safe_event_type . "'           AS event_type, 
           '" . $safe_event_shortdesc . "'      AS event_shortdesc, 
           '" . $safe_event_vanue . "'          AS event_venu, 
           '" . $event_date . "'        AS event_start 
    UNION ALL 
    SELECT customer_id, NULL, NULL, NULL, NULL, NULL
    FROM   customer 
    WHERE  login_id = " . $_SESSION['SESS_LOGIN_ID']; 
    

    Using sample data:

    $safe_videography_package = 'package1';
    $safe_event_type = 'type1';
    $safe_event_shortdesc = 'short description';
    $safe_event_vanue = 'some venu';
    $event_date = '2012-05-05';
    $_SESSION['SESS_LOGIN_ID'] = 1;

    Will produce:

    INSERT INTO event 
                (customer_id, 
                 videography_package, 
                 event_type, 
                 event_shortdesc, 
                 event_vanue, 
                 event_start) 
    SELECT 'customer-id'       AS customer_id, 
           'package1'          AS videography_package, 
           'type1'             AS event_type, 
           'short description' AS event_shortdesc, 
           'some venu'         AS event_venu, 
           '2012-05-05'        AS event_start 
    UNION ALL 
    SELECT customer_id, NULL, NULL, NULL, NULL, NULL
    FROM   customer 
    WHERE  login_id = 1 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me whats wrong with this MySQL query ? select distinct(a.productId) from
Please can anyone tell me what's wrong with this MySQL query SELECT count(items.id) AS
Can anyone tell me what is wrong with this query below? from a programming
I know I have more than one result in the table, can anyone tell
Can anyone tell me what is wrong with this query? it gives a syntax
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone tell me what's wrong with this code? It's giving me an error
Can anyone tell me what is wrong with this code? public abstract class BoardTestBean{
Can anyone tell me where I am going wrong... I am using the following
Anyone can tell me what I'm doing wrong? I am creating a simple system

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.