473,625 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Valid Query? (Insert into, values, select, where)

11 New Member
Is the following a vaild query, or does any one have any suggestion on how to change it to get the correct info i'm looking for?

Expand|Select|Wrap|Line Numbers
  1. $Engineer = $_POST['Engineer'];
  2. $Ref_No = $_POST['Ref_No'];
  3.  
  4. $query = "INSERT INTO engineer (Ref_No,Title,Forename,Surname,Email,Branch,Message,Severity,Engineer)
  5. VALUES('$Engineer')
  6. SELECT Ref_No,Title,Forename,Surname,Email,Branch,Message,Severity FROM new_fault
  7. WHERE ref_no='$Ref_No'";
  8.  
  9. $result = mysqli_query($cxn,$query) or die ('error making query');
  10.  
The table im trying to put info in to is called engineer. I want to input the data from table New_Fault that contains the SELECT values (Ref_No etc) also i want to put in the engineer name from the POST method.
Apr 25 '08 #1
2 3714
r035198x
13,262 MVP
A simple modification to a SELECT INTO statement should have done the trick.
Jun 18 '08 #2
chaarmann
785 Recognized Expert Contributor
as far as I know you cannot use values() and select together.
Just make the engineer value part of the select statement. that means:

[PHP]
$Engineer = $_POST['Engineer'];
$Ref_No = $_POST['Ref_No'];

$query = "INSERT INTO engineer (Ref_No, Title, Forename, Surname, Email, Branch, Message, Severity, Engineer)
SELECT Ref_No, Title, Forename, Surname, Email, Branch, Message, Severity, '$Engineer' as Engineer FROM new_fault
WHERE ref_no='$Ref_No '";

$result = mysqli_query($c xn,$query) or die ('error making query');
[/PHP]
Jun 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1653
by: Philip Hachey | last post by:
I think this is do-able, and possibly even simple, but it's been too many years since I've done anything significant with SQL. Any help would be appreciated. I have two tables, PAY and CHG. PAY contains payments to employees and the dates each payment was made. CHG contains dates employees were hired and to what group they belonged. CHG also contains any changes (updates) to which group they belong along with the effective date of...
4
2492
by: soni29 | last post by:
hi, i need some help with a query, also to find out if this is even possible with sql. currently i have a table with the following data: CustomerNumber CustomerBranch 123 NULL 123 1 123 2 221 NULL 221 5
1
3660
by: per | last post by:
im not very good at sql but need to query the database to use in my programming script. if the database is just like this id name parent_id 1 A null <----- root 2 B 1 3 C 1 4 D 1 5 E 2
4
22698
by: Spark | last post by:
Hi, Situation: Need a query to return number of ticket records by month of open in a log table where the ticket open record is older than 24 hours then the ticket pending or ticket closed record. Tickets can also only have a closed record with no open record. Sample data table: ticket_id date_log status_name status_id
5
3886
by: Muhd | last post by:
To start off i have a database table that consists of "profiles", another that consists of "users" and finally one that consists of "exclusions", these are defined in the DDL below. I am trying to select all the profiles minus any exclusions that are set up for that user but i keep getting duplicate entries for profiles that aren't excluded and single entries for profiles that are excluded. IF EXISTS(SELECT TABLE_NAME FROM...
6
12699
by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a block of "x" number of sequential part numbers - say for example 5. If my database had the following numbers available: 101 104 105 110
3
1733
by: Myron | last post by:
I'm trying to create a query that will tell me which requests took longer than 10 days to move one from particular state to another state. The query I've created returns the correct requests, but not always the correct 'NextActionDate'/'NextStatus'/'NextState'. I'm sure I'm missing something easy, but I can't figure out what it might be. Any help is appreciated! Thanks, Myron -- remove SPAM-KILL from address to reply by email --
5
2334
by: Glenn | last post by:
Hi! Server info - Win2K3 Server +SP1 with 1 GB Memory and 1.5 GB Virtual Memory SQL Server 2000 Enterprise Edition + SP3 running on this. Required result - Create a SQL Script that will contain a set of create, update, insert & delete statements (about 17500 lines including blank lines) that
7
3311
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The view I have works, but doesn't work when I supplement the query with some functions... they just don't like the UNION. The real problem is I can't change any of the udf's or queries, just the view. The view is inner joined back on to the primary...
0
3290
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex queries yes or no, I have prepared an example. The example is a database with the following tables: *table person with fields: -persid: autoincrement id -name: name of the person *table material with fields: -materialid: autoincrement id
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.