This is the scenario:

User A: Access the website and choose a questionnaire. The questionnaires are separated on different pages in the same domain, for example:

Home: "surveys.com"

Questionnaires:

"surveys.com/type1"

"surveys.com/type2"

After choosing one, he (User A) puts the following information:

1 = Recipient's email

2 = His email

And then submit.

User B: Person who received this link to the questionnaire (surveys.com/type1).

What I want to do is: When User B accesses the link to the questionnaire page, it is already programmed to send responses to User A who left his email on the home page.

My idea was to save the information provided by User A in variables and save it in the database. When User B accesses the page, I take the respective information from the database and use it on the page to do what I want.

The problem is: How would I separate information for different users? (maybe it's simple, but I don't know how to do it)

That's what I've done so far:

Home:

<?php

include_once 'includes/dbh.php';
require  'email/PHPMailerAutoload.php';

$recipient = $_POST['emailFor'];
$sender = $_POST['senderEmail'];
$message = $_POST['message'];

$sql = "INSERT INTO users(email, body) VALUES('$sender', '$message');";
mysqli_query($conn, $sql;)

Questionnaire page (survey.com/type1):

<?php

include_once 'includes/dbh.php';
$sql = "SELECT * FROM users;";
$result = mysqli_query($conn, $sql);

?>

I think it is not possible to use sessions, since the information will need to be passed on to another user. I also thought about the possibility of creating a uniq link maybe, but I have no idea how to do it. Anyway, I'll be grateful if you can help with code examples for this.

I think this does need to be a database solution.

So when UserA selects the questionaire and submits form, FIRST the input form's code stores the userA details, userB details and the selected questionaire in a database table, then the actual emailing occurs as the last step, and includes a link to a query to retrieve that one line from the database.
Then UserB clicks on the link, the query runs, and creates a webpage showing the questionaire, UserA's details and User B's details. And sens an email to userA saying UserB (extracted from database) has opened survey x (also extracted from the database.

So effectively UserA populates the database with details of who is getting the survey and what survey it is, and then sends that to UserB who can retrieve everything via the details in the email.

This also means that UserA can separately query the db to see who has received survey details etc. And you can have multiple users assigning surveys and multiple people recieving them, from any one who counts as UserA (or an admin as they might also be called). So I could send survey 1 to fred and jane, while you might send survey 2 to fred and carole and eric. And records of who did what are stored for later retrieval.

It seems a very simple database problem to me. As long as the input form userA uses is protected by passwords.
Perhaps others can give a better summary of what to do than my rough sketch of the steps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.