klinmy Posted March 14, 2006 Share Posted March 14, 2006 when i fill up form A, the information will be displayed in the next page (form B) when i click the "next" button. [!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]example data that i entered in Form A in the 1st time,id = (auto_increment)name=johnsex = maleexample data which is displayed in Form B in the 1st time, id=0 (supposely 221)name=johnsex = male[!--colorc--][/span][!--/colorc--][!--coloro:#993399--][span style=\"color:#993399\"][!--/coloro--]example data that i entered in Form A in the 2nd time,id = (auto_increment)name=selinasex = femaleexample data which is displayed in Form B in the 2nd time, id=221 (supposely 222)name=selinasex = female[!--colorc--][/span][!--/colorc--]the problem is when the first time i fill up the form, the auto_increment id will not be displayed in form B, it will only be displayed with the first id when i fill up for the second time. below is parts of my script in form A, [code]$db=mysql_connect("localhost","ky","pw");if(!$db){ die("Failed to open connection to MySQL server.");}mysql_select_db("onlineleave");check_mysql();if(!isset($id)){ $id=0;}elseif(isset($next)){ if($errors==0) { check_mysql(); $id=mysql_insert_id(); header("Location: applyBa.php?name=$_POST[name]&id=$_POST[id]&sex=$_POST[sex]"); exit; } }<input type="hidden" name="id" <?php echo "VALUE=\"$id\""?>>[/code]Form B[code]<?php echo $_GET[name] ?> is <?php echo $_GET[sex] ?> with ID <?php echo $_GET[id] ?>. if(isset($save)){ $query="INSERT INTO tableB " . "( name, sex) VALUES ( '$name, '$sex)"; $result=mysql_query($query); check_mysql(); $id=mysql_insert_id();[/code] thanksthe id value in the database is correct, just the display in form B has problem. Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 14, 2006 Share Posted March 14, 2006 FORM A:[code]<?php$db=mysql_connect("localhost","ky","pw") or die("MySQL Error: ".mysql_error());mysql_select_db("onlineleave") or die("MySQL Error: ".mysql_error());check_mysql();if(!isset($id)) $id=0;if((isset($next)) && ($errors==0)) { check_mysql(); $id=mysql_insert_id(); header("Location: applyBa.php?name=".$_POST['name']."&id=".$_POST['id']."&sex=".$_POST['sex']); exit;}?><input type="hidden" name="id" value="<?php echo $id; ?>">[/code]FORM B[code]<?phpecho $_GET['name']." is ".$_GET['sex']." with ID ".$_GET['id'].".";?>if(isset($save)) { $query="INSERT INTO tableB (name, sex) VALUES ('".$_GET['name']."', '".$_GET['sex']."')"; $result=mysql_query($query); check_mysql(); $id=mysql_insert_id();}[/code]This is just what I would change from what I can see. Don't assume register globals is on, because it probably isn't and definitely shouldn't. Additionally if you already have a row in the table with the information and you are making changes to it use UPDATE sql query and condition WHERE id=".$_GET['id'].".I hope this is helpful. Quote Link to comment Share on other sites More sharing options...
klinmy Posted March 14, 2006 Author Share Posted March 14, 2006 thanks txmedic03, but all the other values (name and sex) are working fine except for id only.i tried to close my Form B. by running only Form A, nomatter how many times i enter data, the id still remains '0'.. Quote Link to comment Share on other sites More sharing options...
klinmy Posted March 14, 2006 Author Share Posted March 14, 2006 it's the code i tried on form Ai now change the next button to save.[code]mysql_select_db("onlineleave");check_mysql();if(!isset($id)) $id=0;if(isset($save)){ $query="INSERT INTO apply " . "(name, sex) VALUES ( '$name', '$sex')"; $result=mysql_query($query); check_mysql(); $id=mysql_insert_id(); echo "id = $id";}[/code]the message showed the correct id as in database, no problem it seems.but when i bring the info to Form B, [code]if(isset($save)){ $query="INSERT INTO apply " . "( name, sex) VALUES ( '$name', '$sex')"; $result=mysql_query($query); check_mysql(); $id=mysql_insert_id(); header("Location: FormB.php?id=$_POST[id]&name=$_POST[name]&sex=$_POST[sex]");exit; }[/code] and placing this in Form B, [code]<?php echo '<pre>'.print_r($_GET,true).'</pre>'; ?>[/code]it came out like this,Array( [name] => john [id] => 0 [sex] => male)why is it cant get the value id (auto_increment)?thanks alot! Quote Link to comment Share on other sites More sharing options...
shocker-z Posted March 14, 2006 Share Posted March 14, 2006 In form A you set a POST and a GET for ID which are you after? on form B if your after $ids from form A then you need $_POST['id'] but if your after $_POST[id] which has been sent in as id=$_POST[id] in the URL then you are using the correct one.. so which are u wantiong to pull into form B? Quote Link to comment Share on other sites More sharing options...
klinmy Posted March 14, 2006 Author Share Posted March 14, 2006 there isn't any GET for id in Form A. or is there??i'm trying to get the value of id to Form B. i've tried using both $_POST[id] and $_POST['id']. but it just made no different..name and sex can stil get the values as entered in form A Quote Link to comment Share on other sites More sharing options...
klinmy Posted March 14, 2006 Author Share Posted March 14, 2006 it's now working fine after changing to ths..[code]if(isset($save)){ $query="INSERT INTO apply " . "( name, sex) VALUES ( '$name', '$sex')"; $result=mysql_query($query); check_mysql(); $id=mysql_insert_id(); header("Location: FormB.php?id=$id&name=$_POST[name]&sex=$_POST[sex]");exit; }[/code]thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.