I have a page called projects.php to let the users submit their bid information via form. When the user is logged in, he can submit this form. But am not able to find out which user has applied to the job unless I specify a username field in the form itself. Each user has to write his username while submitting this form to let me know they have submitted it. I have mysql set up, where the username is stored. How to connect the username automatically when the user is submitting this form without having to enter his username when logged in.

<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>

<fieldset >
<legend>Apply to work</legend>

<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />

<div class='short_explanation'>* required fields</div>

<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>

<div class='updown'>
    <label for='username' >User Name*:</label><br/>
    <input type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
    <span id='login_username_errorloc' class='error'></span>
</div>

<div class='container'>
    <label for='title'>Work Title*: </label><br/>
    <input type='text' name='title' id='title' value='<?php echo $formproc->SafeDisplay('title') ?>' maxlength="50" /><br/>
    <span id='contactus_title_errorloc' class='error'></span>
</div>
<div class='container'>
    <label for='bid value'>Bid value ( INR )*:</label><br/>
    <input type='number' name='bid' id='bid' value='<?php echo $formproc->SafeDisplay('bid') ?>' maxlength="50" /><br/>
    <span id='contactus_bid_errorloc' class='error'></span>
</div>
<div id="sample">
    <label for='Bidtext'>Cover letter or Bid Text*:</label><br/>
    <textarea name="Bidtext" style="width: 500px; height: 200px;" value='<?php echo $formproc->SafeDisplay('Bidtext') ?>'> </textarea>
                <span id='contactus_Bidtext_errorloc' class='error'></span>

</div>
<div class='container'>
    <label for='resume'>Upload file:</label><br/>
    <input type="file" name='resume' id='resume' /><br/>
    <span id='contactus_resume_errorloc' class='error'></span>
</div>


<div class='container'>
    <input type='submit' name='Submit' value='Submit' />
</div>

</fieldset>
</form>

After submission I get all values of the form except not knowing who filled the form.

Dani AI

Generated

You don’t need the user to type their username. If your login system already shows who’s signed in (you mentioned using the $fgmembersite object), attach that identity on the server when you process the form instead of trusting a form field. Store and use the numeric user ID (or a stable username from the server-side session) when inserting the bid into MySQL — it’s safer and avoids spoofing.

Quick checklist to debug the current flow:

  • Confirm the login code puts a value in session (e.g. $_SESSION['user_id'] or similar).
  • Ensure the form-processing script calls session_start() before reading session data.
  • Don’t rely on a client-sent username field; the processing script should derive the user from the session/auth object.
  • If unsure what’s in the session, temporarily var_dump($_SESSION) while logged in (or log it) to see the keys.

Example server-side pattern (use prepared statements and validate inputs):

session_start();
if (empty($_SESSION['user_id'])) { header('Location: login.php'); exit; }
$user_id = (int) $_SESSION['user_id'];
$title = trim($_POST['title'] ?? '');
$bid = (float) ($_POST['bid'] ?? 0);
$bidtext = trim($_POST['Bidtext'] ?? '');
// use PDO or mysqli prepared statement to insert user_id with the bid

Notes and cautions: store the user_id in the bids table (foreign key) rather than a free-text username. Validate bid as numeric, sanitize text, and handle uploads securely (check MIME/type and use move_uploaded_file). , this removes the need for users to retype names; ’s suggestion to check what session data you have is exactly the right next step.

Recommended Answers

All 3 Replies

To show who is logged in I use - Logged in as : <?= $fgmembersite->UserFullName() ?>
But I am unable to pass the value via the form when the user submits it. I know there is some php syntax which can be used to display which user submitted this form.

I would be glad to listen your voices. I am using sessions already.

Please note that it is not a registration form. I have already set up the register and login form. The above form is a form submission that a user requires to make to apply for works.

What data about the user do you have stored in the session when they're logged in?

Id?
Username?

Be a part of the DaniWeb community

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