PHP Self

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

PHP Self

Post by kumarrana »

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.
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Post by webspider »

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 
}
?>
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

Post by staar2 »

Code: Select all

<form action="PageWhereUserGoesAfterSubmit.php" method="post"></form>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Self

Post by califdon »

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.
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.
User avatar
crystal ship
Forum Commoner
Posts: 36
Joined: Wed Aug 29, 2007 5:45 am

Post by crystal ship »

I don't think we need ajax here. The codes from webspider is enough to do the job.
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

PHP Self

Post by kumarrana »

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.

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";
}
?>
User avatar
crystal ship
Forum Commoner
Posts: 36
Joined: Wed Aug 29, 2007 5:45 am

Post by crystal ship »

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>";
}
?>
Hope what you want is this...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

I believe there is a bit of vital information missing here

Info stated: everything must be done in the same page
Possible meaning: everything must be done without reloading the page

Is possible meaning true or false?
kumarrana
Forum Commoner
Posts: 26
Joined: Sat Sep 01, 2007 12:55 pm

PHP Self

Post by kumarrana »

It worked perfect. Thanks a lot. Appreciate it;
Post Reply