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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arushibafna
    New Member
    • Nov 2009
    • 8

    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..??
  • clai83
    New Member
    • Dec 2007
    • 41

    #2
    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

    Code:
    <form action="submitmarks.php" method="post" id="postExample">
         // whatever your form is
        <input type="hidden" name="var1" value="first variable" />
        <input type="hidden" name="var2" value="second variable" />
    </form>
    
    //alternatively
    
    <form action="submitmarks.php" method="get" id="postExample">
         // notice that the method is now get
        <input type="hidden" name="var1" value="first variable" />
        <input type="hidden" name="var2" value="second variable" />
    </form>
    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.

    Code:
    <?php  
        //Now in PHP you have to process the $_GET or $_POST array
        foreach ($_GET as $key => $value) {
             // in the example above the $keys would be "var1" and "var2"
             echo $key." = ".$value; //just prints key a value pair to the screen
        }
    
       // OR if you used the POST method then 
       foreach ($_POST as $key => $value) {
             // in the example above the $keys would be "var1" and "var2"
             echo $key." = ".$value; //just prints key a value pair to the screen
        }
       
    ?>
    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.



    Comment

    • arushibafna
      New Member
      • Nov 2009
      • 8

      #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-
      Code:
      <form method="get" action="check.php">
      	 
      <input type="text" name="marks" /><br/>
      <input type="text" name="marks" /><br/>
      <input type="text" name="marks" /><br/>
      <input type="text" name="marks" /><br/>
      <input type="text" name="marks" /><br/>
      <input type="submit" value="Submit" name="submit" />
      </form>
      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?

      Comment

      • arushibafna
        New Member
        • Nov 2009
        • 8

        #4
        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-
        Code:
        <form method="get" action="check.php">
        	 
        <input type="text" name="marks" /><br/>
        <input type="text" name="marks" /><br/>
        <input type="text" name="marks" /><br/>
        <input type="text" name="marks" /><br/>
        <input type="text" name="marks" /><br/>
        <input type="submit" value="Submit" name="submit" />
        </form>
        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?

        Comment

        Working...