Jump to content

[SOLVED] How to pass value by header?


Piba

Recommended Posts

Hello quys,

I have a question please,

I have a multi-page form, and i post values from one page to another just like this:

<input type=hidden name=q1 value=$_POST[q1]>
....

Ofcourse, this will be by making the action=page1.php in form tag, first page

 

Here is the problem: in page2, there is radio button(yse-no) ,if the user choose yse, then he will goes to page3

While if he choose no, the page will direct him to page4

 

I wrote something like this:

<form action="page3.php" method="post">
<table>
.....
<input name=q1 type=radio value=0>Yes
<input name=q1 type=radio value=1>No
<input name=id type=hidden value=$id>
.....
</table>
</form>

 

In page3:

if($_POST[q1]==1)
header("location:page4.php");
else
{
.... body of page3
}

 

So, if i'm in page3, i can see the hidden input

But how if i'm in page4?? with header the hidden will be lost!!!

So how could i make something like this???

 

Thanks

 

Regards,

Piba

 

Link to comment
Share on other sites

I assume you're referring to the $id value? Pass it in the URL and retrieve it from the $_GET array:

 

header("location:page4.php?id=".$_POST['id']);

 

//page 4
echo 'ID: '.$_GET['id'];

 

 

However, wouldn't it be easier to track the ID with a session? Then you wouldn't have to worry about passing it around all over the place and, assuming the ID isn't supplied by the user, you wouldn't have to worry about it being changed by the user.

Link to comment
Share on other sites

I assume you're referring to the $id value? Pass it in the URL and retrieve it from the $_GET array:

 

header("location:page4.php?id=".$_POST['id']);

 

//page 4
echo 'ID: '.$_GET['id'];

 

 

However, wouldn't it be easier to track the ID with a session? Then you wouldn't have to worry about passing it around all over the place and, assuming the ID isn't supplied by the user, you wouldn't have to worry about it being changed by the user.

 

Hello GingerRobot,

Thanks for replying:)

But i don't want to transfer the id through url, that will be visible to users

I want through $_POST

 

For session:

Actually i used before in this form session method, but i got alot of problem, Not in programming but in saving data

I will explain to you my old way using session, so if you can help, this would be better

i have a multi-page form, lets say from 4 pages...

in the first page, insert empty values in table1 to get automatic id for user:

mysql_query("INSERT INTO table1 VALUES('0','0000-00-00','0')");
$id=mysql_insert_id();
$_SESSION['id']=$id;
session_write_close();

After that, i save user's answers in table1,2,3,4 WHERE id=$_SESSION[id]

And ofcourse update table1 WHERE id=$_SESSION[id]

 

Also, each page there will be check if user fill the page before or not

 

My problem is when two users at the same time start filling the form, the session is changed and user1 got an error message that he already filled this page (according to user2 session not his)

 

I dont know excatly what is the problem???

 

Can you figure out??

 

Thanks

Link to comment
Share on other sites

Well this kind of thing realy is a job for sessions. A user could quite easily see the ID by taking a glance at the source and it is easily modified too.

 

Sessions shouldn't behave like that - they are user independant, so i suspect something else is going on here. Is that the actual query you were using? There doesn't appear to be a field that you're leaving blank which would correspond to the auto-incremented ID.

 

I take it this wasn't two users on the same computer?

Link to comment
Share on other sites

No, they were'nt two users on the same computer

Maybe it's not overlapping, but i really dont know why user2 got error msg while he just start the form

Ok.. I will place here the code, and explain it:

First when the user open page1,fill and press button(Go to next stage) i will save in table4 an empty record:

$table4= "INSERT INTO table4 VALUES('0','0000-00-00','0', '0')";
@mysql_query($fourth) or die(mysql_error());
$id=mysql_insert_id();
$_SESSION[id']=$id;
session_write_close();

the first field of table4 is auto-increment id

and then i will save the first page value:

$table1= "INSERT INTO table1 VALUES('0', curdate(), '$_SESSION[id]', '$_POST[q1]','$_POST[q2]','$_POST[q3]')";
@mysql_query($table1) or die(mysql_error());
header("location:page2.php");

Ok..the page2 first check if user filled this page before or not:

if(!(isset($_SESSION[id'])))
header("location:errormsg1.php");   // the user is trying to access page2 before answer page1

$get_id=mysql_query("select user_id  from table2 where user_id ='$_SESSION[id]'");
if(mysql_num_rows($get_id_res)!=0)
  header("location:errormsg2.php");  //if the user filled this page before
else
{
  body of page2
}

Then when he press button(Go to next stage) i will save in table2:

$table2= "INSERT INTO table2 VALUES('0', curdate(), '$_SESSION[id]', '$_POST[q1]','$_POST[q2]','$_POST[q3]')";
@mysql_query($table2) or die(mysql_error());
header("location:page3.php");

 

The same for page3 and page4, except that in page4 will be updated:

$table4= "UPDATE table4 SET date=curdate(), name='$_POST[name]', age='$_POST[age]' WHERE id=$_SESSION[user_id]";
@mysql_query($table4) or die(mysql_error());
header("location:index.php");

 

I see that the record in table4 with id=1 is replaced with record of id=2

 

And sometimes as i said before, when user2 going from page1 to page2, errormsg2 tells him that he filled before!!!!

 

Is there any problem with my query??

 

I'm really got confiused ??? ???

 

Thanks alot GingerRobot for helping

Link to comment
Share on other sites

Only if you give it incorrect information to hold.

 

You have a problem here:

 

[b]$table4[/b]= "INSERT INTO table4 VALUES('0','0000-00-00','0', '0')";
@mysql_query([b]$fourth[/b]) or die(mysql_error());
$id=mysql_insert_id();
$_SESSION[id']=$id;
session_write_close();

 

Which may very likely be causing all your troubles.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.