PHP Self
Moderator: General Moderators
PHP Self
I created a form for user. I know how to dump stuff in MySQL after user hits submit in an another page. But I have been trying to have everything in same page. Moreover I want to hide user form after user hit submit. Can anybody write a sample code, on how to process after user hits submit.
i think you can do this using an if-else condition
Code: Select all
<?php
if(isset($_POST['submit'])){
// dump stuff in mysql
}
else
{
//show the form to user
}
?>Code: Select all
<form action="PageWhereUserGoesAfterSubmit.php" method="post"></form>Re: PHP Self
You are describing exactly what Ajax does. Using Javascript, and specifically the built-in Javascript class XMLHttpRequest (see http://www.w3schools.com/xml/xml_http.asp), it fetches data from the server and makes it available to code in the same page, so you can remove unwanted document elements, insert new data, etc. Usually you do this using the HTML DOM property ".innerHTML", which every open/close tag HTML element has.kumarrana wrote:I created a form for user. I know how to dump stuff in MySQL after user hits submit in an another page. But I have been trying to have everything in same page. Moreover I want to hide user form after user hit submit. Can anybody write a sample code, on how to process after user hits submit.
- crystal ship
- Forum Commoner
- Posts: 36
- Joined: Wed Aug 29, 2007 5:45 am
PHP Self
With your help I went this far. I don't know much about Ajax so, I just sticked with what I know.
My problem is even after submit button it does nothing.
My problem is even after submit button it does nothing.
Code: Select all
<?php
echo "<form action=\"$PHP_SELF\" method=\"POST\">";
echo "Username:
<input name=username type=text>
<span class=style1>*</span>
<br> <br>
Password:
<input name=password type=password>
<span class=style1>*</span><br>
<br>
E-mail:
<input name=email type=text>
<span class=style1>*</span><br>
<br>
Name :
<input name=name type=text><br>
<input name=submit type=button value=Create Account>
</form>";
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$name = $_POST['name'];
echo " Do something $username";
echo "Do something";
}
?>- crystal ship
- Forum Commoner
- Posts: 36
- Joined: Wed Aug 29, 2007 5:45 am
Code: Select all
<?php
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$name = $_POST['name'];
echo " Do something $username";
echo "Do something";
}else{
echo "<form action=\"$PHP_SELF\" method=\"POST\">";
echo "Username:
<input name=username type=text>
<span class=style1>*</span>
<br> <br>
Password:
<input name=password type=password>
<span class=style1>*</span><br>
<br>
E-mail:
<input name=email type=text>
<span class=style1>*</span><br>
<br>
Name :
<input name=name type=text><br>
<input name=submit type=submit value=Create Account>
</form>";
}
?>- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California