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 ","\nLINE 3: (,,,,,,,,,,,) \n ^
Many thanks in advance
7 2278
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.
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,...
|
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...
|
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...
|
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...
|
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.
------------------------------------------------------------
--...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |