brownbrod Posted January 19, 2015 Share Posted January 19, 2015 (edited) Hi, I am doing a survey and need a little guidance. I have data being selected from one table and I am trying to store it in another. I have no problem selecting the data and displaying it, I just can't get it to continue on with the new survey. Here is the file showing the data collected: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Question 1</title> </head> <body> <?php session_start(); $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; ?> Name: <?php echo $_POST['name'];?><br> CS Login: <?php echo $_POST['cslogin'];?><br> Domain: <?php echo $_POST['domain'];?><br> Project: <?php echo $_POST['project'];?><br> ODM: <?php echo $_POST['ODM'];?><br> HW Phase: <?php echo $_POST['hwphase'];?><br> PPM ID: <?php echo $_POST['ppmid'];?><br> Survey: <?php echo $_POST['survey'];?><br> Month: <?php echo $_POST['month'];?><br> Everything from table 1 is displayed above. No problem. Here is the next page after this. Question #1 has already been answered: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Question 2</title> </head> <body> <?php session_start(); $name = $_SESSION['name']; $cslogin = $_SESSION['cslogin']; $domain = $_SESSION['domain']; $project = $_SESSION['project']; $ODM = $_SESSION['ODM']; $hwphase = $_SESSION['hwphase']; $ppmid = $_SESSION['ppmid']; $survey = $_SESSION['survey']; $month = $_SESSION['month']; $Q1 = $_SESSION['Q1']; $comment1 = $_SESSION['comment1']; ?> Name: <?php echo $_SESSION['name'];?><br> Q1: <?php echo $_SESSION['Q1'];?><br> Comments: <?php echo $_SESSION['comment1'];?><br> It displays question 1 and comments with no problem. This is where the "name - month" is lost. How would I have name - month continue on to be store in a new table? I greatly appreciate your help. Thanks!! Note: based on the question for #1, the user is redirected to question 2 or question 3. Here is the file that is between Q1 and Q2 <?php session_start(); $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; $_SESSION['Q1'] = $_POST['Q1']; $_SESSION['comment1'] = $_POST['comment1']; switch ($_POST['Q1']) { case "No": $url = "filename"; break; case "Yes": $url = "http://odmQ3_a.php"; break; case "Supplier Assessment is ongoing and issues still being worked": $url = "odmQ3_a.php"; } header("Location: $url"); ?> Edited January 19, 2015 by Ch0cu3r Added code tags Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/ Share on other sites More sharing options...
Ch0cu3r Posted January 19, 2015 Share Posted January 19, 2015 I have no idea what you are asking. But I can tell you are using session_start() incorrectly. It should only used before any output, this includes code that is outside of the php tags too. NOTE: When posting code please wrap it within tags or click the <> button in the editor. I have edited your post for you. Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503404 Share on other sites More sharing options...
brownbrod Posted January 19, 2015 Author Share Posted January 19, 2015 What I am doing is pulling the name and login stored in one table and trying to copy it to another along with additional information I need to collect. Is there a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503410 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 How are you re-sending the POST data to that intermediate page? If you aren't then all the session vars will be overwritten and set to empty. Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503430 Share on other sites More sharing options...
brownbrod Posted January 19, 2015 Author Share Posted January 19, 2015 The next page after the POST data page is this: <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Question 2</title></head><body><?phpsession_start();$name = $_SESSION['name'];$cslogin = $_SESSION['cslogin'];$domain = $_SESSION['domain'];$project = $_SESSION['project'];$ODM = $_SESSION['ODM'];$hwphase = $_SESSION['hwphase'];$ppmid = $_SESSION['ppmid'];$survey = $_SESSION['survey'];$month = $_SESSION['month'];$Q1 = $_SESSION['Q1'];$comment1 = $_SESSION['comment1'];?>Name: <?php echo $_SESSION['name'];?><br>Q1: <?php echo $_SESSION['Q1'];?><br>Comments: <?php echo $_SESSION['comment1'];?><br> Is this where I am loosing the data? How would I re-send the POST data? I greatly appreciate it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503440 Share on other sites More sharing options...
Barand Posted January 19, 2015 Share Posted January 19, 2015 Let me get it straight. You have a page that does this $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; Then a page that decides whether to go to Q2 or Q3 that does this (even though there is no mention of Q2) $_SESSION['name'] = $_POST['name']; $_SESSION['cslogin'] = $_POST['cslogin']; $_SESSION['domain'] = $_POST['domain']; $_SESSION['project'] = $_POST['project']; $_SESSION['ODM'] = $_POST['ODM']; $_SESSION['hwphase'] = $_POST['hwphase']; $_SESSION['ppmid'] = $_POST['ppmid']; $_SESSION['survey'] = $_POST['survey']; $_SESSION['month'] = $_POST['month']; $_SESSION['Q1'] = $_POST['Q1']; $_SESSION['comment1'] = $_POST['comment1']; then the Q2 page <title>Question 2</title> </head> <body> <?php session_start(); $name = $_SESSION['name']; $cslogin = $_SESSION['cslogin']; $domain = $_SESSION['domain']; $project = $_SESSION['project']; $ODM = $_SESSION['ODM']; $hwphase = $_SESSION['hwphase']; $ppmid = $_SESSION['ppmid']; $survey = $_SESSION['survey']; $month = $_SESSION['month']; So my question was "When going to the second above, how are the POST vars re-sent?" You wouldn't need to - just re-use the session vars. Don't reset them to the (empty) post vars. Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503445 Share on other sites More sharing options...
brownbrod Posted January 19, 2015 Author Share Posted January 19, 2015 Yes, I have this first: session_start(); $_SESSION['name'] = $_POST['name'];$_SESSION['cslogin'] = $_POST['cslogin'];$_SESSION['domain'] = $_POST['domain'];$_SESSION['project'] = $_POST['project'];$_SESSION['ODM'] = $_POST['ODM'];$_SESSION['hwphase'] = $_POST['hwphase'];$_SESSION['ppmid'] = $_POST['ppmid'];$_SESSION['survey'] = $_POST['survey'];$_SESSION['month'] = $_POST['month']; Then it is directed to this: session_start(); $_SESSION['name'] = $_POST['name'];$_SESSION['cslogin'] = $_POST['cslogin'];$_SESSION['domain'] = $_POST['domain'];$_SESSION['project'] = $_POST['project'];$_SESSION['ODM'] = $_POST['ODM'];$_SESSION['hwphase'] = $_POST['hwphase'];$_SESSION['ppmid'] = $_POST['ppmid'];$_SESSION['survey'] = $_POST['survey'];$_SESSION['month'] = $_POST['month'];$_SESSION['Q1'] = $_POST['Q1'];$_SESSION['comment1'] = $_POST['comment1']; The for the question 2 start I have this: session_start(); $name = $_SESSION['name'];$cslogin = $_SESSION['cslogin'];$domain = $_SESSION['domain'];$project = $_SESSION['project'];$ODM = $_SESSION['ODM'];$hwphase = $_SESSION['hwphase'];$ppmid = $_SESSION['ppmid'];$survey = $_SESSION['survey'];$month = $_SESSION['month'];$Q1 = $_SESSION['Q1'];$comment1 = $_SESSION['comment1']; So I should eliminate question 2 start and leave it as is? Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503449 Share on other sites More sharing options...
Solution Barand Posted January 19, 2015 Solution Share Posted January 19, 2015 If I understand right, the second block above should be like the third, not using POSTs that don't exist. Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503457 Share on other sites More sharing options...
brownbrod Posted January 19, 2015 Author Share Posted January 19, 2015 Thank you!! That's what was wrong!!! I greatly appreciate your help. Have a wonderful day!!! Quote Link to comment https://forums.phpfreaks.com/topic/294063-collect-data-and-use-in-another/#findComment-1503461 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.