1

I have a php file that contains a form (which contains 2 input boxes and a submit button) for updating a contact. I managed to fill the fields with the contact's data, but I can't detect if the submit button is clicked

form looks like this

echo "<form action=Contact.php><table>".
"<tr><td>First Name</td><td><input type=text size=75% name=FirstName value='".$row['FirstName']."'></td></tr>".
"<tr><td>Last Name</td><td><input type=text size=75% name=LastName value='".$row['LastName']."'></td></tr>".
"<tr><td colspan=2><input type=submit name=UpdateContact value=Update></td></tr>".
"</table></form>";

this code should output a "clicked" message if the button is clicked

if (isset($_POST['UpdateContact']))
{
   echo "<p>clicked";
}
else
{
   echo "<p>not clicked";
}

can anyone help me out or tell me what i've done wrong

(I want from the same php file to fill the contact's data in a from and to update the database)

1

2 Answers 2

4

The default method for a form is GET, so either set the form's method attribute to "post", or change your $_POST in PHP to $_GET.

echo "<form method=post action=Contact.php><table>".
"<tr><td>First Name</td><td><input type=text size=75% name=FirstName value='".$row['FirstName']."'></td></tr>".
"<tr><td>Last Name</td><td><input type=text size=75% name=LastName value='".$row['LastName']."'></td></tr>".
"<tr><td colspan=2><input type=submit name=UpdateContact value=Update></td></tr>".
"</table></form>";

or

if (isset($_GET['UpdateContact']))
{
   echo "<p>clicked";
}
else
{
   echo "<p>not clicked";
}
Sign up to request clarification or add additional context in comments.

Comments

0

are you sure your code is reaching the php file. If yes, then the first think to check is the request type.. using $_SERVER['REQUEST_METHOD']

it will give POST in case the button was click and GET in case it the page was accessed using URL like.. google.com/Contact.php. also, u might ned to add METHOD ="POST" in the first line of form action "form action=Contact.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.