473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

how to get values in array on other page and then enter it in database..

hey,
while working on my project, i encountered a problem .here's the description-
a teacher is required to insert marks of 15 students.( 15 is just the random no. , it can vary) . so a page is displayed with the roll no. and names with a text box in front of each in which marks have to be entered..a sort of table. and in the end teacher clicks submit.
now please anyone tell me how do get all the values on the php page and insert them in correct order in my database..?? it has to be done through array or some special function, if so , how? or anyone can suggest me a better way to insert the marks..??
Nov 29 '09 #1
3 2059
clai83
41
arushibafna-

Could you give the specific code of your html form you are using or something similar so people can better answer you question?

For now I can give you this

If you submit a form you have to set a method. POST, or GET. Also please look at this reference on PHP predefined variables http://www.php.net/manual/en/reserved.variables.php

Expand|Select|Wrap|Line Numbers
  1. <form action="submitmarks.php" method="post" id="postExample">
  2.      // whatever your form is
  3.     <input type="hidden" name="var1" value="first variable" />
  4.     <input type="hidden" name="var2" value="second variable" />
  5. </form>
  6.  
  7. //alternatively
  8.  
  9. <form action="submitmarks.php" method="get" id="postExample">
  10.      // notice that the method is now get
  11.     <input type="hidden" name="var1" value="first variable" />
  12.     <input type="hidden" name="var2" value="second variable" />
  13. </form>
  14.  
Now depending on the method the data extraction process in your submitmarks.php will be slightly different.

I am not including data and data error processing in this example, but it is HIGHLY recommended that you do so.

Expand|Select|Wrap|Line Numbers
  1. <?php  
  2.     //Now in PHP you have to process the $_GET or $_POST array
  3.     foreach ($_GET as $key => $value) {
  4.          // in the example above the $keys would be "var1" and "var2"
  5.          echo $key." = ".$value; //just prints key a value pair to the screen
  6.     }
  7.  
  8.    // OR if you used the POST method then 
  9.    foreach ($_POST as $key => $value) {
  10.          // in the example above the $keys would be "var1" and "var2"
  11.          echo $key." = ".$value; //just prints key a value pair to the screen
  12.     }
  13.  
  14. ?>
  15.  
As far as inserting data into your database that is another story. You have not posted what database you are using. Since you are using PHP though a lot of PHP goes with the MySQL RDBMS. SQL is another subject on its own but here is a link to the mysqli and pdo database-access abstraction layers to get you started.

http://ca3.php.net/manual/en/book.mysqli.php

http://ca3.php.net/manual/en/book.pdo.php
Nov 29 '09 #2
hey
well, its not possible me to give u the whole html code here as i havnt made it..
but here's an extract , the part mainly concerned-
Expand|Select|Wrap|Line Numbers
  1. <form method="get" action="check.php">
  2.  
  3. <input type="text" name="marks" /><br/>
  4. <input type="text" name="marks" /><br/>
  5. <input type="text" name="marks" /><br/>
  6. <input type="text" name="marks" /><br/>
  7. <input type="text" name="marks" /><br/>
  8. <input type="submit" value="Submit" name="submit" />
  9. </form>
  10.  
now first u might point out that the name of all the variables are same. so let me clear u that its a self generated code depending on the no. given by the user..
i have tried "get" here just to check if my values are being transfered or not. they are..
now my ques is how do i collect the values of these same named variable"marks" in an array...on my php page?
Nov 29 '09 #3
hey
well, its not possible me to give u the whole html code here as i havnt made it..
but here's an extract , the part mainly concerned-
Expand|Select|Wrap|Line Numbers
  1. <form method="get" action="check.php">
  2.  
  3. <input type="text" name="marks" /><br/>
  4. <input type="text" name="marks" /><br/>
  5. <input type="text" name="marks" /><br/>
  6. <input type="text" name="marks" /><br/>
  7. <input type="text" name="marks" /><br/>
  8. <input type="submit" value="Submit" name="submit" />
  9. </form>
  10.  
now first u might point out that the name of all the variables are same. so let me clear u that its a self generated code depending on the no. given by the user..
i have tried "get" here just to check if my values are being transfered or not. they are..
now my ques is how do i collect the values of these same named variable"marks" in an array...on my php page?
Nov 29 '09 #4

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

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
2
by: John Wilson | last post by:
Hello friends, I have this dynamic array(shown below) that I need to match to values (1 - 10) that I am returning from the database via DSN connection object. The values I need to match are on...
1
by: Sue Adams | last post by:
I have a form on an asp page and am trying to write the code to place the values of all checkboxes that have been selected, into an array. The checkbox values will be used in a dynamic sql statement...
6
by: gv | last post by:
Hi all, I need to store values in a client application then later when done send them to SQL 2000. I know there is several ways to do this but, looking for the fastest , and most effient way...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
3
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.