Hi everyone,
I have a form in “test.php” which I want to process in “test1.php”.
test.php is the following:
<!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> </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 !
<?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 !
HTTP GET is only meant to retrieve data. Any sort of mutation on the server side (storing stuff to the database for example) must be done in a POST request.
Saving data without a submit button can be done using AJAX, but if you’re not sure if your current code works I’d make sure it works first before going any further.
Your <a href> link just takes you directly to test1.php without any of the form contents, because it has nothing to do with the form. The fact that you displayed it inside the form is neither here nor there, it’s just a hyperlink.
As @rpkamp said, you can do it with Ajax. You could also use CSS to style your submit button, or use an image or something else.
From the Title of the Thread:
Can you set $_GET? Yes. $_GET is a malleable array.
Should you? No.
From the actual post:
What you’re trying to do is doable without AJAX, but it’s a Javascript manipulation still.
It would be easier with AJAX instead, and manipulating a button’s onclick event, but strictly from what the OP has asked, it can be done.
What he’s trying to do is the following (pseudocode):
on input change:
this.parent.find('a').href = 'test1.php'+urlEncode(this.parent)
Make a function to check everything you want has been set, and then if it has, submit the form:
function submitIfFormComplete()
{
// Check the select has something selected
if (document.getElementById('selectOne').selectedIndex > 0)
{
document.getElementById('formID').submit();
}
}
Then on your select, bind the onchange event to run the function.
function checkAndSubmit()
{
if (document.getElementById('sel1').selectedIndex > 0
&& document.getElementById('sel2').selectedIndex > 0)
{
//document.getElementById('formID').submit();
alert('both have been selected!');
}
}
I’ve replaced the submit with an alert() to show you how the code triggers.
Edit: You can use $_REQUEST['selectCar'] to access the value.
PHP runs before the page loads. Once it hands the data to the user’s client, it’s done until the user sends another request to the server.
Any reaction to something the user does (fill in a box, move the mouse, whatever) that does not involve sending a request back to the server is Javascript’s domain.