Hi,
I want to insert multiple rows in a database table, from an submit form. But not able to trouble shoot the problem in my code. Following is the code. - <form action=test_insert.php method="post">
-
<table>
-
<?php for($i=0; $i<10; $i++)
-
{ ?>
-
-
<tr>
-
<td><input type="text" name="employee_id" value="0" size = "2" ></td>
-
<td><input type="text" name="task_no" value="0" size = "2" ></td>
-
<td><input type="text" name="discription" value="0" size = "2"></td>
-
<td><input type="text" name="mon" value="0" size = "2"></td>
-
<td><input type="text" name="tue" value="0" size = "2"></td>
-
<td><input type="text" name="wed" value="0" size = "2"></td>
-
<td><input type="text" name="thu" value="0" size = "2"></td>
-
<td><input type="text" name="fri" value="0" size = "2"></td>
-
<td><input type="text" name="sat" value="0" size = "2"></td>
-
<td><input type="text" name="sun" value="0" size = "2"></td>
-
<td><input type="text" name="total" value="0" size = "2"></td>
-
<td><input type="text" name="week_no" value="0" size = "2"></td>
-
</tr>
-
<?php } ?>
-
-
</table>
-
-
<input name="submit" value="Submit" type="submit">
-
</form>
-
-
<?php
-
$conn = pg_connect("host=localhost port=5432 dbname=*** user=postgres password=*****");
-
-
$query = "insert into public.grid_data (employee_id, task_no, discription, mon, tue, wed, thu, fri, sat, sun, total, week_no)
-
Values
-
($employee_id,$task_no,$discription,$mon,$tue,$wed,$thu,$fri,$sat,$sun,$total,$week_no) ";
-
-
$res = pg_query($conn, $query) or die(pg_last_error());
-
if($res){echo("Record added for : $employee_id");}
-
-
?>
-
The 2 errors which I am gettin are. 1. undefined variable for all ( $employee_id, $task_no .....) and
2. Query failed: ERROR: syntax error at or near ","\n LINE 3: (,,,,,,,,,,,) \n ^
Many thanks in advance
7 2299 Markus 6,050
Recognized Expert Expert
You are not defining the variables anywhere in your script.
I changed my sql query to - $query = "insert into public.grid_data (employee_id, task_no, discription, mon, tue, wed, thu, fri, sat, sun, total, week_no)
-
Values
-
('$_POST[employee_id]','$_POST[task_no]','$_POST[discription]','$_POST[mon]','$_POST[tue]','$_POST[wed]','$_POST[thu]','$_POST[fri]','$_POST[sat]','$_POST[sun]','$_POST[total]','$_POST[week_no]') ";
It inserts one row in the table now. But not 10
Because there are 10 rows in the form, in which user is inptting different values. I Just figured out may be I need an array in the input type name of every td, and then a loop at the insert statement.
Dormilich 8,658
Recognized Expert Moderator Expert
They're all the same name though.
having a form with inputs like this: -
<input type="text" name="sun" value="0" size = "2">
-
<input type="text" name="sun" value="0" size = "2">
-
Means that only one sun will be shown.
To acheive what you want you need to name them: - <input type="text" name="sun[]" value="0" size = "2">
-
<input type="text" name="sun[]" value="0" size = "2">
Then after you POST you must look through them all like sooo.. - foreach($_POST['sun'] as $x=>$Value)
-
{
-
$_POST['mon'][$x] // means if $x is 2 it will get mon[2]
-
}
Guys, Thank you very much an array at input type name and a loop at insert statement did my job. :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Martin |
last post by:
Hello,
I'm new with triggers and I can not find any good example on how to
do the following:
I have two tables WO and PM with the following fields:
WO.WONUM, VARCHAR(10)
WO.PMNUM, VARCHAR(10)
WO.PROBLEMCODE, VARCHAR(8)
|
by: Python_it |
last post by:
Python 2.4
MySQL-python.exe-1.2.0.win32-py2.4.zip
How can I insert a NULL value in a table (MySQL-database).
I can't set a var to NULL? Or is there a other possibility?
My var must be variable string or NULL.
Becaus i have a if statement:
if ....
cursor.execute(".................insert NULL ..............")
if ....
|
by: Paul Shaw |
last post by:
Can anyone explain why an insert might cause multiple logical
bufferpool data reads?
Here's a situation that has me scratching my head.
Table A's data resides in tablespace B
Table A's indexes reside in tablespace C
Table A has no long data
No other data resides in either of these tablespaces.
|
by: Roy Gourgi |
last post by:
Hi,
I am trying to add a row to my table but I get the error message
"invalid column name SOBN and BN1" on this statement. Basically, I am trying
to add the row into the same table that I am searching if it does not find
SOBN = 5 and BN1 =3. What is the problem? Do I have to create a primary
key? Is it possible to have more than 1 primary key (i.e. secondary
....... ).
strCommand = "INSERT INTO tblSQL_2 (SOBN, BN1) SELECT SOBN , BN1...
|
by: Sezai YILMAZ |
last post by:
Hello
I need high throughput while inserting into PostgreSQL. Because of that I
did some PostgreSQL insert performance tests.
------------------------------------------------------------
-- Test schema
create table logs (
logid serial primary key,
ctime integer not null,
| |
by: robecflo |
last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm
developing with windows forms and vb.net, and oracle as a database. At
this moment i have a table called amortizaciones, this table has a
field called id_pasivo, which is foreign key to another table called
pasivo, a consecutive field called no_cupon and a third field called
date. So when i make a query (i.e select * from amortizaciones where
id_pasivo = 522 order by...
|
by: dunleav1 |
last post by:
I have a process that does inserts that runs 50% slower that Oracle and
Mssql.
Queries normally take 50% slower than normal.
DB2, Oracle, Mssql all are configured on same os, same disk array (raid
1/0 - 15k disks) but DB2 I/O seems to be significantly slower.
Tablespaces are SMS with automatic prefetch set.
My thought was to create the log buffer array as large as possible so I
don't have to switch to disk much. I'm running circular...
|
by: Robert Bravery |
last post by:
HI all,
VS 2005 C# MSSQL2005
I have a parent child grandchild related tables. Claimheader, claim (deteails), claimfinancialloss
When ever I try to add row to claimfinancialloss table, I get this error, if and only if the claim detail table is empty:
Obviously as the foreign key is 0.
System.Data.SqlClient.SqlException was unhandled
Message="The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_Claim_claimheader\". The...
|
by: cday119 |
last post by:
Can someone help me out with this one. I am trying to insert a row of data into an access database. The primary key is set to auto increment. It will work once but the next time you try an insert it says. "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. " This error occurs on the daComputers.Update(dsHardware, "Computers") line
Here is the...
|
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: 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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |