Send Value to second page? SOLVED

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
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Send Value to second page? SOLVED

Post by ridshack »

I cant really figure out how to send the value for a record just entered to a second page.

BTW: I have done a few hours of research on Google and a forum or two but cant actually get anything to work.

The last thing I tried is

First Page

Code: Select all

$id = printf("%d\n", mysql_insert_id());
echo $_POST['id'];
Second Page

Code: Select all

echo $_REQUEST['id'];
echo $id;
Any help is greatly appreciated.

Ridshack
Last edited by ridshack on Thu Oct 12, 2006 2:08 am, edited 1 time in total.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

In order to pass a superglobal like $_POST you need to use a form

depending on your purposes something like this would pass data to another page

Code: Select all

<form method="POST" action="2nd_page.php">
<h1>name </h1>
<input type="text" name="name">
<input type="submit" name="submit" value="submit your name">
</form>
2nd_page.php

Code: Select all

<?php
echo $_POST['name'];
?>

IF you just want to pass data from page to page you could use a hidden form value instead.

hope this helped.

-Sean
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Still a little confused.

Post by ridshack »

Thank you for your reply. I can’t figure out how this value will get passed to a second page since I don’t have the value of the record entered until after the form is submitted to the database.

Ridshack
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

I don't know MySQL yet :oops:

But I would say, you enter the value, then SELECT * FROM db and the ROW which you need to query, then echo that into the second page. Just look up a basic MySQL tutorial you'll find very quickly the answer to your questions i'm sure.
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Post by ridshack »

I cant get the value $id value to the second page in order to query MySql and pull the data.

Im posting the form data to the same page

Code: Select all

<form method="post" action="<?php echo $thispage; ?>?proc=New&post=yes&<?php echo $pagevars; ?>
I may be going about it all wrong. All I want is a print page, but I need the unique ID displayed with all the data inputted from the form submission.
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Post by ridshack »

Page1.php Code inserted after the form was entered into the database.

Code: Select all

$a_id = mysql_insert_id();
        //Redirects to the print.php page
        header( 'Location: print.php?a_id=' . $a_id);
Page2.php

Code: Select all

<?php
	$a_id = $_GET['a_id'];
	echo "$a_id;"
	?>

I got the tip needed from this post.

viewtopic.php?t=54602&highlight=mysqlinsertid

Thanks for the support.

Ridshack
Post Reply