Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Form submission and MySQL retrieval
Old 01-07-2010, 04:41 PM Form submission and MySQL retrieval
Junior Talker

Posts: 2
Name: Jordan
Trades: 0
Hi all,

I'm running on a limited knowledge of PHP, but I've been able to use intuition to get by up till now... I've got a problem, and I can't figure out the solution.

I managed to create a dynamic dropdown menu that populates itself with names from a MySQL table, with the option values being the IDs on the table. Using $_POST, the form sends the option value to another PHP page to execute the action.

I've confirmed that the action page IS receiving the proper ID number.

What I want to do is use PHP and the ID to retrieve the rest of the information relevant to that ID from the table and display it. (i.e., if I selected name#2, who's option value is 2, I want the action page to retrieve and display the rest of that entry (like phone number, email, etc.)

I have a feeling it's probably a fairly simple solution, I've just run out of ideas.

Help? Please and thank you
Paxfia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-07-2010, 04:59 PM Re: Form submission and MySQL retrieval
xela1966's Avatar
Super Talker

Posts: 135
Name: Baptista
Location: Alvor, Algarve Portugal
Trades: 0
I like to use php and as you do, I can figure and change my scripts and I had no problems. Maybee some one have a proper anser for you but I will try to use a hidden input filed with the data you get from database and then just collect the data from there.
__________________
Algarve Holidays
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
xela1966 is offline
Reply With Quote
View Public Profile Visit xela1966's homepage!
 
Old 01-07-2010, 06:31 PM Re: Form submission and MySQL retrieval
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I've re-read 3 times, but I'm still not sure I have understood it...

So, you have 1 page, call it "select.php" that generate a drop down from your db.
When you choose an option in that drop down, it redirect you to another page, let's call it "action.php".
You verified that action.php received the ID correctly.

Now, do you want action.php to display you other infos relevant to the id, or do you want to be redirected to another page that does display those infos?

If it's the first case, you need to query the db again, with the given id, to fetch the details.

If it's the second case, the easiest way to keep the id between the pages is to put it's value into $_SESSION, redirect to the page that fetch the infos from the id, and cleanup the id from the session.

And if your question is "how do I get the infos ?"
then, although you'll need to adapt to your db structure:
PHP Code:
$id=$_SESSION['user_id'];  //or $_POST, but you let yourself open to sql injection that way.
$user=null;
if(
$id!==null){
  
$sql="select * from users where id=$id";
  
$r=mysql_query($sql);
  while(
$o=mysql_fetch_array()){
    
$user=$o;
  }
}

if(
$user!==null){
  foreach(
$user as $key=>$value){
    echo 
"<hr/>$key is $value";
  }

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-07-2010, 09:30 PM Re: Form submission and MySQL retrieval
Junior Talker

Posts: 2
Name: Jordan
Trades: 0
@Tripy,

Everything works, thank you so much! I knew the answer was going to be fairly simple.
Paxfia is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Form submission and MySQL retrieval
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13651 seconds with 12 queries