Hi Im doing a questionnaire in PHP and MYSQL
I am trying to do a multiple insert using the following code
[PHP]$query1 = "INSERT INTO answers (answer_score,q uestion_id,user _id) VALUES ('$item1','$que stion[0]','$user_id_for eign'), ('$item2','$que stion[1]','$user_id_for eign')";[/PHP]
But it will only insert the first value and not the second. I have tested the mysql bit of coding in mysql itself with some values I manuall input i.e.: -
(4, 1, 1), (3, 2, 1) and this inserted both sets of values. I have tried splitting them up into seperate queries but the exact same thing happens.
From what I can tell I believe it is to do with my values for the user_id, I am inserting the user_id with a variable I have called $user_id_foreig n. Due to the lack of proper foreign keys in the versions I have (v 4.1) I am having to count up the number of users in the table put them in DESC order and then add 1 for the next user_id. This works like a charm but as there are 75 questions I need this same ID to be repeated 75 times.
Another possibility is that of the answers (1 to 7) which are stored as strings in $item1, $item2 and so on till $item75
Any help would be gratelly appreciated
Thanks
Nabz
2 4041
Hi.
It seems that the '$foreign_user_ id' has the same value in both records. So 1st record is inserted while 2nd is not.
As you are adding 1 to your user id for each record you should do something like -
-
$query1 = "INSERT INTO answers (answer_score,question_id,user_id) VALUES"
-
- for each record
-
-
$item = item of question num
-
$Question = question num
-
etc
-
-
-
-
$query1 =$query1 . " ('$item','$question','$user_id_foreign'), "
-
- increment user_id_foreign
-
-
end for
-
-
-
Hi.
It seems that the '$foreign_user_ id' has the same value in both records. So 1st record is inserted while 2nd is not.
As you are adding 1 to your user id for each record you should do something like -
-
$query1 = "INSERT INTO answers (answer_score,question_id,user_id) VALUES"
-
- for each record
-
-
$item = item of question num
-
$Question = question num
-
etc
-
-
-
-
$query1 =$query1 . " ('$item','$question','$user_id_foreign'), "
-
- increment user_id_foreign
-
-
end for
-
-
-
Cheers mate
That worked like a charm
Thanks
Nabz
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jack |
last post by:
I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:
INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");
INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");
INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
|
by: Rudi Ahlers |
last post by:
A different question though. Is it possible to delete duplicate entries,
where the email address is the same, and only keep one?
i.e..
I got say 4 DB entries, all with the same email address, and I want to
delete 3. How do I do this?
--
Kind Regards
|
by: Michael Schoen |
last post by:
Hi there,
i=B4m actually developing a performance criticial system where I need to
index a huge amount of protocoll data.
These data are already in a chronological order, so if I push the data
one by one in the database I will never need an ORDER BY syntax, `cause
mysql already stores the data the right way. That=B4s tweaking, isn=B4t it
;)
|
by: Tim Hastings |
last post by:
Hello,
I am using MyODBC from VB and I want to submit a batch of insert statements
in one call from my App. This is more efficient than making multiple calls
from code because of the communication overhead.
If I send a batch multiple statements separated by ; or ; + newline I get
syntax errors pointing at the start of the next statement..
If I fire each statement one at a time with the ; at the end there's no
problem.
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest version of this document can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
| |
by: kristof.loots |
last post by:
Hi all,
Somehow I want to transfer data from an mysql database on the web to an
local offline access database. Note: tables and types do not match.
So, I toughed, generating sql commands to insert the data would do the
trick. But, unfortunately it works only properly for 1 record.
This is what I do (suggestions are more than welcome)
Create a new query, skip all the wizard-stuff and choose sql-view. Then
I past my dozen sql commands...
|
by: Atli |
last post by:
Hi.
I've been trying to insert multiple rows into a table using a single INSERT statement in MSSQL / SQL Server 2005.
I could of course cheat and have my C# code insert each row using some sort of a loop, but where is the fun in that :-)
If you'r familliar with MySQL, this MySQL query would do what I am trying to do with MSSQL / SQL Server 2005.
INSERT INTO
UserInfo(InfoName, InfoValue)
VALUES
|
by: paulq182 |
last post by:
PLEASE HELP ME WITH MY CODE??
import java.sql.*;
import java.io.*;
class min_filmdb_rel_mysql {
public static void main (String args )
throws SQLException, IOException {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |