473,788 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Not able to insert new rows in a database table

36 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. <form action=test_insert.php method="post">
  2. <table>
  3. <?php for($i=0; $i<10; $i++)
  4. { ?>
  5.  
  6.     <tr>
  7.     <td><input type="text" name="employee_id" value="0" size = "2" ></td>
  8.     <td><input type="text" name="task_no" value="0" size = "2" ></td>
  9.     <td><input type="text" name="discription" value="0" size = "2"></td>
  10.     <td><input type="text" name="mon" value="0" size = "2"></td>
  11.     <td><input type="text" name="tue" value="0" size = "2"></td>
  12.         <td><input type="text" name="wed" value="0" size = "2"></td>
  13.         <td><input type="text" name="thu" value="0" size = "2"></td>
  14.         <td><input type="text" name="fri" value="0" size = "2"></td>
  15.         <td><input type="text" name="sat" value="0" size = "2"></td>
  16.         <td><input type="text" name="sun" value="0" size = "2"></td>
  17.     <td><input type="text" name="total" value="0" size = "2"></td>          
  18.     <td><input type="text" name="week_no" value="0" size = "2"></td>
  19.     </tr>
  20. <?php } ?>
  21.  
  22. </table>
  23.  
  24. <input name="submit" value="Submit" type="submit">
  25. </form>
  26.  
  27. <?php
  28. $conn = pg_connect("host=localhost port=5432 dbname=*** user=postgres password=*****");
  29.  
  30. $query = "insert into public.grid_data (employee_id, task_no, discription, mon, tue, wed, thu, fri, sat, sun, total, week_no)
  31. Values
  32. ($employee_id,$task_no,$discription,$mon,$tue,$wed,$thu,$fri,$sat,$sun,$total,$week_no) ";
  33.  
  34. $res = pg_query($conn, $query) or die(pg_last_error());
  35. if($res){echo("Record added for : $employee_id");}
  36.  
  37. ?>
  38.  
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 &quot;,&quot;\n LINE 3: (,,,,,,,,,,,) \n ^

Many thanks in advance
Sep 29 '09 #1
7 2299
Markus
6,050 Recognized Expert Expert
You are not defining the variables anywhere in your script.
Sep 29 '09 #2
tarunkhatri
36 New Member
I changed my sql query to

Expand|Select|Wrap|Line Numbers
  1. $query = "insert into public.grid_data (employee_id, task_no, discription, mon, tue, wed, thu, fri, sat, sun, total, week_no)
  2. Values
  3. ('$_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
Sep 29 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@tarunkhatri
why should it insert 10 rows?
Sep 29 '09 #4
tarunkhatri
36 New Member
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.
Sep 29 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
that sounds reasonable.
Sep 29 '09 #6
88stevie
4 New Member
They're all the same name though.

having a form with inputs like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="sun" value="0" size = "2">
  2. <input type="text" name="sun" value="0" size = "2">
  3.  
Means that only one sun will be shown.

To acheive what you want you need to name them:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="sun[]" value="0" size = "2">
  2. <input type="text" name="sun[]" value="0" size = "2">
Then after you POST you must look through them all like sooo..

Expand|Select|Wrap|Line Numbers
  1. foreach($_POST['sun'] as $x=>$Value)
  2. {
  3.   $_POST['mon'][$x] // means if $x is 2 it will get mon[2]
  4. }
Sep 29 '09 #7
tarunkhatri
36 New Member
Guys, Thank you very much an array at input type name and a loop at insert statement did my job. :)
Sep 29 '09 #8

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

Similar topics

9
3462
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)
10
52801
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 ....
5
4135
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.
6
27863
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...
11
9220
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,
5
4074
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...
46
13148
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...
0
2651
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...
2
1988
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...
0
9656
marktang
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...
0
9498
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
10366
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
10173
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...
1
10110
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,...
1
7517
isladogs
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...
0
5399
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...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
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...

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.