Jump to content

$_POST Problem


chaychie

Recommended Posts

Hi guys, I have the following code which works well.

 

The code is to display all the data from the database in input text field format. User is able to edit and update the details by clicking the update button at the end of each row to update the specific row.

 

Instead of clicking the update button one by one (if user want to edit and update more than one row), now I would like to create a hyperlink which will update ALL the data at once.

 

The problem now is I dunno how to pass the value of $_post to the "update.php" since I already have

 

   <form name="form1" action="submitAction.php" method="post">

 

I am not sure is it possible to do so. Or is there any other alternative ways?

 

Thanks in advanced! =)

 

    <html>
    <script language="javascript" >
    <!-- hide
    function submitRequest(id) {
    document.forms[id].submit();
    }
    // end hide -->
    </script>
    
    <!-- The Javasript (Onclick) to Remove the Readonly Attribute-->
    <script language="JavaScript">
      function removeAlignment(id){
       document.getElementById("ProjectName_"+id).removeAttribute("readonly",0);
       document.getElementById("DeviceType_"+id).removeAttribute("readonly",0);
      }
    </script>
    
    <body>
    <?php
    
    $counter=1;
    //Connecting and Accessing the Database 
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("Project", $con);
    
    $result = mysql_query("SELECT * FROM Project where status='Ongoing'");
    
    ?>
    
    <p><h2 align="center">ADC Project Funnel</h2></p>
    <table border="1" bordercolor="lavender" cellspacing="0" cellpadding="0">
      <tr>
        <td width="20" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">No</font></b></td>
        <td width="78" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Project
          Name</font></b></td>
        <td width="72" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Device Type</font></b></td>
        <td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial">Status</font></b></td>
        <td width="67" bgcolor="steelblue" height="15" style="font-size: 11" align="center"><b><font face="Arial"></font></b></td>
      </tr>
      <tr>
      <td colspan="15" height="15" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Current Project Assignment</font></td>
      </tr>
      
      <!-- Records from the database (Current Project Assignment) -->
      <?php 
      $i = 0;
        while ($row=mysql_fetch_array($result)){
      ?>
        <tr>
        <form name="form1" action="submitAction.php" method="post">
        <td height="5" width="20"  align="center" style="font-size: 13" valign="middle"><?php echo $counter; ?></td>
        <td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="ProjectName_<?php echo $i; ?>" name="ProjectName<?php echo $row['No'];?>" value="<?php echo  $row['ProjectName'];?>" size="20" style="font-size: 10"></font></td>
        <td height="5" width="72" ><input type="text" autocomplete=off readonly="readonly" id="DeviceType_<?php echo $i; ?>" name="DeviceType<?php echo $row['No'];?>" value="<?php echo  $row['DeviceType'];?>" size="15" style="font-size: 10"></font></td>
        <td height="5" width="67" style="font-size: 13">
        <select name="action" onchange="submitRequest(<?php echo $i; ?>);">
        <option value=>Ongoing </option>
        <option value="<?php echo $row['ProjectName'];?>">Complete</option>
        <option value="<?php echo $row['Flag2'];?>">Future</option>
        <option value="<?php echo $row['Flag1'];?>">Cancel</option>
        <option value="<?php echo $row['No'];?>">Update</option>
        <option value="<?php echo $row['Flag3'];?>">Delete</option>
        </select>								    
        </td>
        <td height="5" width="64" ><input type="button" style="width:100%" value="Edit" onclick="removeAlignment(<?php echo $i; ?>);"></td>
        </tr>
        </form> 
        <?php 
      
        ?>
           
      <?php 
      $i++;
      $counter++;
      }
      ?>   
          
    
      <tr>
      <td colspan="16" bgcolor="#AFEEEE"><font face="Arial" size="1.9">Add New Project Assignment</font></td>
      </tr>
      
       <!-- Add New Records -->
      <tr>
       <form action="project_insert.php" method="post">
         <td width="20" ></td>
         <td width="78" ><input type="text" autocomplete=off name="ProjectName"  size="40" style="font-size: 10"></font></td>
         <td width="72" ><input type="text" autocomplete=off name="DeviceType" size="15" style="font-size: 10"></font>
         <td width="80" style="font-size: 13">
         	 <select name="Status" style="width:100%">
         	 	<option value=Future>Future</option>
         	 	<option value=Ongoing>Ongoing</option> 	      
    	     </select>	    
    	   </td>
    	   <td>
    	   	<input type="Submit" style="width:100%"value="Add">
    	   	
    	   </td>
    	 </form>
      </tr>
    </table>
    <br/>
    
    <table border="0" align="center" cellpadding="0" cellspacing="10">
    	<tr>
             <td valign="middle"><a href="http://localhost/Project/update.php">update</a></td>
     
      </tr>
    </table>
    
    <br/>
    </body>
    </html>

 

Link to comment
Share on other sites

Either that, or if it's needed in more than one place assign it to a $_SESSION variable when it gets returned to submitAction.php.

 

Just make sure you session_start(); at the beginning of all your scripts which require the variables.

Link to comment
Share on other sites

Hi, I am not sure how to assign $_post value from the form to a $_SESSION variable. Any idea how to do it? Let say the name of the input text is

 

name="ProjectName<?php echo $row['No'];?>"

 

Besides that, Im having problem changing the form action to update.php since the form already submitting data to submitAction.php

Link to comment
Share on other sites

All you do is put a line in submitAction.php which would process the variable and assign it.

 

eg. if your $_POST variable was called test. you do the following.

 

$_SESSION['test']=$_POST['test'];

 

Then provided you have declared session_start(); at the beginning of every script, you can use $_SESSION['test'] in every script after it has been set.

Link to comment
Share on other sites

Storing POST data in the session is not the right way to do it. At what point do you clear it? What if they don't go far enough to clear it, and then re-visit the page and want to use different data? You then have a contaminated session forcing them to use the same data. Yes you could probably add in lots of logic to prevent that happening, but why go to the effort when there's a better, more appropriate way of doing it?

 

Besides that, Im having problem changing the form action to update.php since the form already submitting data to submitAction.php

 

Why do you need to submit to "submitAction.php" first? Why not just submit straight to "update.php"? That's what you should really be trying to do, instead of using session variables for something they're not meant for.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.