Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 14-07-2011, 04:09 AM   #1 (permalink)
learn more share more....
 
hacklinux's Avatar
 
Join Date: May 2011
Posts: 36
Exclamation using php


i have been having this doubt lately that,when you get details from a user on a form using php.then how do i display the details on another page?and is it possible to display only one detail of that user?

help me at the earliest.thanks in advance.
hacklinux is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 14-07-2011, 08:07 AM   #2 (permalink)
change is constant!!
 
khmadhu's Avatar
 
Join Date: Jan 2010
Location: Bengaluru
Posts: 445
Default Re: using php

yes you can display the form values to another page. you should mention the action and method(POST or GET) in form. and at the other end retrieve it through $_GET or $_POST,

if you don't mention method default is GET

here is quick example..

The example below contains an HTML form with two input fields and a submit button:

form page
Quote:
<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

</body>
</html>
When a user fills out the form above and click on the submit button, the form data is sent to a PHP file, called "welcome.php":

"welcome.php" looks like this:
Quote:
<html>
<body>

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.

</body>
</html>
__________________
If you really wanna think, try to think from Atom to Universe!!

cpu: core i5 2500k, mobo: DP67BG, RAM:Corsair 8GB(4x2) 1600 Mhz, XFX HD 5770, 1TB seagate 6Gbps 7200 rpm , SAGA II 500W
khmadhu is offline   Reply With Quote
Old 15-07-2011, 08:45 PM   #3 (permalink)
learn more share more....
 
hacklinux's Avatar
 
Join Date: May 2011
Posts: 36
Default Re: using php

thanks for the answer.but ya i know this.now if i link welcome.php to some other page and i need to display the "name" on that page.how to do that?
hacklinux is offline   Reply With Quote
Old 15-07-2011, 09:27 PM   #4 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: using php

You can store that name in session.

In welcome.php, add
Code:
session_start();
to the first(top), and then do
Code:
$_SESSION['name'] = $_POST['name'];
and then on any page you can call...
Code:
echo $_SESSION['name'];
to display the name.

Or you can use cookies too.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 16-07-2011, 03:10 AM   #5 (permalink)
learn more share more....
 
hacklinux's Avatar
 
Join Date: May 2011
Posts: 36
Default Re: using php

thank you so much.now it is stored in a variable.if i store it in a database and how do i call only that particular name?hope you understood my question.
hacklinux is offline   Reply With Quote
Old 16-07-2011, 09:31 AM   #6 (permalink)
change is constant!!
 
khmadhu's Avatar
 
Join Date: Jan 2010
Location: Bengaluru
Posts: 445
Question Re: using php

Quote:
Originally Posted by hacklinux View Post
now it is stored in a variable.if i store it in a database and how do i call only that particular name?hope you understood my question.

@hacklinux
what r u exactly trying to achieve..? please elaborate u r problem..
__________________
If you really wanna think, try to think from Atom to Universe!!

cpu: core i5 2500k, mobo: DP67BG, RAM:Corsair 8GB(4x2) 1600 Mhz, XFX HD 5770, 1TB seagate 6Gbps 7200 rpm , SAGA II 500W
khmadhu is offline   Reply With Quote
Old 16-07-2011, 07:31 PM   #7 (permalink)
learn more share more....
 
hacklinux's Avatar
 
Join Date: May 2011
Posts: 36
Default Re: using php

@rashmi37 i knw about the adding the data to db.for example:

1.i enter a name "varun".
2.it should get saved in the db.
3.now the name "varun" should be called from the db.


in simple words i want the user data to be saved and displayed to the user simultaneously.
hacklinux is offline   Reply With Quote
Old 16-07-2011, 07:47 PM   #8 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: using php

Hey that was spam. Anyway tell us what you want to achieve.

Looks like you are trying some wrong way.

Still, if you want to sore the name in database and retrieve it from database...here is an example...

You need to have a table. So for eg. assume your database name is test, table name is tbltest, and the field you want to store the name is simply name.

PHP Code:
<?php

//Get the value from form and store it in a variable
$name $_POST['name'];

//Connect MySQL Database
$link mysql_connect("localhost""root""root") or die(mysql_error());
mysql_select_db("test");

//Insert name into MySQL Database
$query "INSERT INTO tbltest(name) VALUES('" $name "')";
mysql_query($query$link) or die(mysql_error());

//Retrieve name from MySQL Database
$query "SELECT * FROM tbltest WHERE name =" $name;
$result mysql_query($query$link) or die(mysql_error());
$row mysql_fetch_row($result);
echo 
$row['name'];

//Close the Connection
mysql_close($link);
?>
Now see, while fetching the value, you can fetch the whole table using SELECT * FROM tbltest. But that would fetch all the names you have inserted, which I'm sure you don't want. And the example that I showed you, the where is clause is simply vogus, but I didn't find any other way out to show you. So you'd need a where clause, which depends on what you actually want to implement.

Even the avobe example looks much vogus to me. So tell us what you want to achieve, we can suggest you better code.

This is just an example, in real life we should implement, if $link > 1, to verify whether the database have been connected or not, though die() ensures that here, then mysql_num_rows($result) > 1, to verify whether any data has been fetched or not before populating that data, to avoid errors, etc.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:31 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2