mysql - php form get parameters from url and store it until the final page -
i wrote simple php survey application movies , using 1 of crowdsourcing services collect data. in order verify , rate workers, have generate vcode (https://microworkers.com/vcode.php) in final page , workers can submit proof of finishing task.
i have give url users: http://www.yourwebsite.com/start.php?campaign={{camp_id}}&worker={{mw_id}}
and user see url this:(numbers inserted crowdsourcing site , worker_id unique each worker) http://www.yourwebsite.com/start.php?campaign=ab1234&worker=cd456
now problem: need parameters (campaign , worker ids) , keep them through end of survey. in way, website able generate correct vcode accepted crowdsourcing system. don't know why null
values.
this how collected values on first index.php page:
$campaign_id = $_get["campaign"]; $worker_id = $_get["worker"];
and after page there php page insert login values (such email or password), wrote:
$sql = "insert member (worker_id, password, email, confirmcode) values (:worker_id, :password, :email, :confirmcode)"; $stmt = $conn->prepare($sql); $stmt->execute(array(':password' => $password, ':email' => $emailtrimmed, ':confirmcode' => $activation, 'worker_id' => $worker_id)); $stmt->closecursor();
but when check db, inserted null worker_id.
i know code has problems, because in first page used forms , of them use "post" method. 1 of these form login , when user click "login", action "sendemail.php" page in insert users' info (such email, pass , worker_id in db). don't know problem because method post , used _get? if yes, should do, because think should not change post get, since have password "post" recommended. or, if problem because had write "$worker_id = $_get["worker"]; in index page?
i confused, hope can me.
it looks - may wrong please clarify incorrect assumptions - looks there potentially several issues here:
get , post different. use
$_request['var']
select or post (i think post overwrites values in situation, if both supplied)in reloading index.php page several times several stages of survey each time reload values need recreated $_get / $_post / $_session / $_cookie data, recommend:
- either setting captured
$_request['worker']
/$_request['campaign']
values hidden fields in survey form on each stage they're (re)submitted each time new page reached, , passed along process start finish, remember using$_request
value pick both/either$_get
,$_post
data. - or, values captured (from original/first
$_get
clause) set them$_session
variables , call these on final stage.
- either setting captured
as wider aspect, run if queries check database functionality called if $_request
(or $_session
, if path chosen) values set and/or non-empty.
it useful debugging output these values on each stage/page of process see these values "dropped". such using
print_r($_request);
we need see more complete view of details of php page give more specific advice, in general check php error log file (don't know, try error_reporting(e_all); ini_set('display_errors', true);
@ top of page and/or check various php error log questions on stackoverflow, there many). , see if error log comes sql specific error such sql worker_id column infact numeric auto-increment whereas given example data alphanumeric. causes error , sql not write data row.
anyhow, luck,
ps -> personal note prefer use single quotes declaring array values
edit: adding hidden values forms:
<form> .... <input type="hidden" name="worker" value="<?php print $worker_id;?>" > <input type="hidden" name="campaign" value="<?php print $campaign_id;?>" > ... </form>
from page loads either original $_get or form data (including page loading example form above) can have $_get/$_post replaced :
$campaign_id = $_request['campaign']; $worker_id = $_request['worker'];
this means forms send data when form submitted , not need add values form submission field specified in <form action="here">
Comments
Post a Comment