Page 2 of 4
Posted: Wed Dec 13, 2006 10:34 am
by RobertGonzalez
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.
Posted: Wed Dec 13, 2006 10:41 am
by neel_basu
Its Working Perfectly If One Pass the GET Variables Through URL
Then Whats The Problem You Think ??
Is It for Header ??
Posted: Wed Dec 13, 2006 10:54 am
by mohson
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?
Posted: Wed Dec 13, 2006 11:03 am
by RobertGonzalez
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:
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!';
}
?>
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
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 ...
}
?>
Posted: Thu Dec 14, 2006 6:06 am
by mohson
Thanks for your reply.
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));
}
And
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]; }
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
Posted: Thu Dec 14, 2006 7:12 am
by neel_basu
neel_basu wrote:neel_basu wrote:Save The Page Where The
<?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]; }
?>
Is As some_file_name.
php
And Use
header ("location:
http://www.soi.city.ac.uk/organisation/ ... id=$org_id")
I Am Telling You Again Just Do This Once What I Have Told You Before. Try This Ones
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
Posted: Thu Dec 14, 2006 8:02 am
by mohson
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
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]; }
?>
It simply prints out the message but doesnt print the org_id
Posted: Thu Dec 14, 2006 8:55 am
by neel_basu
Replace
Code: Select all
header ("location:http://www.soi.city.ac.uk/organisation/pl/CMS/Uorgs.php?Sent=true&id=$org_id");
With
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";
}
And Tell What Is Being Printed
//**************************//
//**This Is For Testing Purpouse**//
//*************************//
Posted: Thu Dec 14, 2006 8:59 am
by mohson
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";
}
?>
I used that and this is what printed
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
Posted: Thu Dec 14, 2006 9:03 am
by neel_basu
mohson wrote: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";
}
?>
I used that and this is what printed
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
No You Didn't Did That I Told You To Replace It Not To Add It
Replace It
Posted: Thu Dec 14, 2006 9:06 am
by neel_basu
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));
}
Posted: Thu Dec 14, 2006 9:09 am
by mohson
ooops sorry neel.
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));
}
And got this:
Posted: Thu Dec 14, 2006 9:13 am
by neel_basu
Yes!
Thats The Actual Thruth And That I suspected
$org_id Is Not Getting Any value Assigned On It
Posted: Thu Dec 14, 2006 9:14 am
by neel_basu
So I Think You have Understood Whats The Actuall Error
Posted: Thu Dec 14, 2006 9:18 am
by mohson
But it is the last 8 records have all got an org_id assigned to it the process code works fine and auto increments an org id, when I search for the record it clearly shows the assigned org_id from 761 to 769