Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I set $_GET[] without "Submit"? 1

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
I have a form in "test.php" which I want to process in "test1.php".
test.php is the following:
Code:
<!DOCTYPE html>
<html>
<head>
  <title>Update Records In MYSQL Database Using PHP</title>
</head>
<body>
  <!--connecting to database-->
  
  <table>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
    </tr>
    <?php
      while($row = mysqli_fetch_array($records))
      {
        echo "<tr><form action = 'test1.php' method = 'GET'>";
        echo "<td><input type = 'text' name = 'mkt_id' value = '".$row['id']."'></td>";
        echo "<td><input type = 'text' name = 'mkt_name' value = '".$row['name']."'></td>";
        echo "<td><a href='test1.php?edit_task=".$row['id']."'>edit</a></td>";
        echo "</form></tr>";
      }
    ?>	
  </table>
</body>		
</html>
I can change the data in test's text boxes as I wish but do the changes take place?
Because "test1.php" when activated by clicking the link, shows the original values !
Code:
<?php
  echo $_GET["edit_task"];
?>
I think that if I sent data wherby a "Submit" button' changes would take place but I try to do it without a Submit button.
Is that possible ? How?
Thanks !
 
I see, a continuation. Good idea to start a new thread, though.

You have to understand your browser does not know anything about the PHP code that created the HTML it received, so the link you se in your PHP code, that both the link you create with the edit_taks URL parameter and the input named 'mkt_id' get their initial value from $row]id].

But that $row]id}is a PHP variable. The browser doesn't get hands on the PHP process and its memory, PHP ended already, it has generated the HTML code that has some specific value , eg 1 put into both places, so your input element starts off as [tt]<input type = 'text' name = 'mkt_id' value = '1'>[/tt] and the link href attribute is as in [tt]<a href='test1.php?edit_task=1'>edit</a>[/tt].

The browser gets the 1 in both places, but just like two letters e in any text. There is no relation or dependency or link or binding between these two 1s. What you edit in HTML is the value of the input element, and only that value, you don't change the URL parameter at the same time just because that 1 once was in a PHP variable not at all existing an more.

And that's why I said in your other thread434-1789092 a link within a form that targets another script is unusual and unintuitive.
All you want is the edited values and so you don't need a link the user clicks on, you need a submit button. And you define the HTML form action to call test1.php if you first want to keep the code of generating the form and processing the edited values separated.

What you experience and haven't wrapped your head around yet is that the server side PHP script generating HTML and the browser rendering it run sequentially and not at the same time and totally independent from each other. The PHP code has ended and the initial request of test.php is done when the HTML form is shown.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Thank you so much Olaf for allocating of your time to make things clearer for me.
I'll do as you suggested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top