Printing some results on screen when submit is selected
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You totally do not have to use a header redirect for this. All you need to do is retrieve the last insert ID from the insert using mysql_insert_id() and if that is set to something, tell the code to show the next form and the value returned from mysql_insert_id(). Adding header redirects is pointless if you are staying on your own server.
Everah wrote:You totally do not have to use a header redirect for this. All you need to do is retrieve the last insert ID from the insert using mysql_insert_id() and if that is set to something, tell the code to show the next form and the value returned from mysql_insert_id(). Adding header redirects is pointless if you are staying on your own server.
Ok Thanks,
But I currently do use a header redirect, all my insert pages redirect the user to a blank form. So how would I work round this using my method?
Can you see anything wrong with the current code?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
If you are currently using the header redirect, then continue to use it. Just pass the last insert id to the next page in the query string (as has been suggested already). Something like:
Keep in mind that there are some things to watch for when using mysql_insert_id(). I would strongly suggest you read the PHP manual on it for more information.
On your resulting page that you are forwarded to, you grab the last inserted id by the $_GET array value:
Code: Select all
<?php
// Default id value
$last_id = 0;
// Insert data
$sql = "INSERT INTO `myTable` (`id`, `lastName`, `firstName`) VALUES ('', 'Jones', 'Billy Bob')";
$result = mysql_query($sql) or die(mysql_error());
// If the query actually inserted something...
if (mysql_affected_rows())
{
// get the last insert id
$last_id = mysql_insert_id();
}
if ($last_id != 0)
{
header('Location: http://www.yourdomain.com/yourprocessin ... ?fetchid=' . $last_id);
}
else
{
echo 'The last id was not updated!';
}
?>On your resulting page that you are forwarded to, you grab the last inserted id by the $_GET array value:
Code: Select all
<?php
if (isset($_GET['fetchid']))
{
// The querystring var was set, validate it then use it
// I WILL LEAVE VALIDATION UP TO YOU
$last_id = $_GET['fetchid'];
// Carry on ...
}
?>Thanks for your reply.
Neel_Basu suggestion seems to work on his side.
So what is wrong with this.
And
Why wont it print out the Org_id All I get is the entire message and "Your org id is"
I get where your coming from with your suggestion, but looking at my current code It seems I am only a little way off solving this but cant discover the error in these two bits code
Neel_Basu suggestion seems to work on his side.
So what is wrong with this.
Code: Select all
header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.html?Sent=true&id=$org_id");
} else {
die ( mysql_error($link));
}Code: Select all
if ((isset($_GET['Sent'])) and ($_GET['Sent'] == 'true')) { echo '<b><font color="#FF0000">New Organisation Added, Add Another? Remember to Search for the Organisation and note the OID before Adding the Person Linked to the created Organisation</font></b>Your org id is'.$_GET[id]; }I get where your coming from with your suggestion, but looking at my current code It seems I am only a little way off solving this but cant discover the error in these two bits code
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
I Am Telling You Again Just Do This Once What I Have Told You Before. Try This Onesneel_basu wrote:neel_basu wrote:Save The Page Where TheIs As some_file_name.php<?php
if ((isset($_GET['Sent'])) and ($_GET['Sent'] == 'true')) { echo '<b><font color="#FF0000">New Organisation Added, Add Another? Remember to Search for the Organisation and note the OID before Adding the Person Linked to the created Organisation</font></b>Your org id is'.$_GET[id]; }
?>
And Use
header ("location:http://www.soi.city.ac.uk/organisation/ ... id=$org_id")
And I Think I Have Told You Before That I Was Using php extension And It was Working.Whats Your Problem If You Use php Extension
OK.
I have done this.
I created a new file called Uorgs.php And Copied all the code to it.
I changed the header redirect to this new file.
AND still the same result
It simply prints out the message but doesnt print the org_id
I have done this.
I created a new file called Uorgs.php And Copied all the code to it.
I changed the header redirect to this new file.
AND still the same result
Code: Select all
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')";
if ($result = mysql_query($sql,$link)) {
header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php?Sent=true&id=$org_id");
} else {
die ( mysql_error($link));
}
?>Code: Select all
<?php
if ((isset($_GET['Sent'])) and ($_GET['Sent'] == 'true')) { echo '<b><font color="#FF0000">New Organisation Added, Add Another? Remember to Search for the Organisation and note the OID before Adding the Person Linked to the created Organisation</font></b>Your org id is'.$_GET[id]; }
?>- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Replace
With
And Tell What Is Being Printed
//**************************//
//**This Is For Testing Purpouse**//
//*************************//
Code: Select all
header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php?Sent=true&id=$org_id");Code: Select all
if($org_id || !empty($org_id) || isset($org_id))
{
header ("location:http://localhost/tmp_rapid_php/tmp_rcv.php?Sent=true&id=$org_id");
}
else
{
echo "\$org_id Has No Value Assined";
}//**************************//
//**This Is For Testing Purpouse**//
//*************************//
Code: Select all
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')";
if ($result = mysql_query($sql,$link)) {
header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php?Sent=true&id=$org_id");
} else {
die ( mysql_error($link));
}
if($org_id || !empty($org_id) || isset($org_id))
{
header ("location:http://localhost/tmp_rapid_php/tmp_rcv.php?Sent=true&id=$org_id");
}
else
{
echo "\$org_id Has No Value Assined";
}
?>New Organisation Added, Add Another? Remember to Search for the Organisation and note the OID before Adding the Person Linked to the created OrganisationYour org id is
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
No You Didn't Did That I Told You To Replace It Not To Add Itmohson wrote:I used that and this is what printedCode: Select all
mysql_select_db("contact_management_system",$link) or die("Could not select database"); $sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')"; if ($result = mysql_query($sql,$link)) { header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php?Sent=true&id=$org_id"); } else { die ( mysql_error($link)); } if($org_id || !empty($org_id) || isset($org_id)) { header ("location:http://localhost/tmp_rapid_php/tmp_rcv.php?Sent=true&id=$org_id"); } else { echo "\$org_id Has No Value Assined"; } ?>
New Organisation Added, Add Another? Remember to Search for the Organisation and note the OID before Adding the Person Linked to the created OrganisationYour org id is
Replace It
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
After Replacing It Would Look Like Like This
==============================
==============================
Code: Select all
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')";
if ($result = mysql_query($sql,$link))
{
if($org_id || !empty($org_id) || isset($org_id))
{
header ("location:http://localhost/tmp_rapid_php/tmp_rcv.php?Sent=true&id=$org_id");
}
else
{
echo "\$org_id Has No Value Assined";
}
}
else
{
die (mysql_error($link));
}ooops sorry neel.
I did this
And got this:
I did this
Code: Select all
mysql_select_db("contact_management_system",$link) or die("Could not select database");
$sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')";
if ($result = mysql_query($sql,$link)) {
if($org_id || !empty($org_id) || isset($org_id))
{
header ("location:http://localhost/tmp_rapid_php/tmp_rcv.php?Sent=true&id=$org_id");
}
else
{
echo "\$org_id Has No Value Assined";
}
} else {
die ( mysql_error($link));
}Code: Select all
$org_id Has No Value Assined