Jump to content

[SOLVED] Autofill form after login


taz321

Recommended Posts

Hi

 

I am trying to do 2 things here, im trying to autofill a client form.

 

1) A person would login to a system by using their username and password.

2) The next page they enter is a form which they must fill in.

3) I want different bits of the form already filled with details of the user that has logged in such as the persons name & teamname.

 

This is the code for the user log-in.

 

<?php

session_start();

require "connect.php";

$username = $_GET['username'];

$password = $_GET['password'];

$query = "select * from client where username='".$username."' AND password='".$password."'";

 

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

 

$row=mysql_fetch_array($result);

 

if($row != null)

{

$_SESSION['username'] = $row['username'];

header("Location: ClientForm.php");

exit();

}

else

{

$message = "Invalid UserName or Password, Please Try Again";

header("Location: ClientLogin.php?message=$message");

exit();

}

?>

 

 

This is the code for the form, where it would add to the database once the form has been submitted.

I want the foriegn keys in this also be filled in with the same details of the person.

 

<?php

require "connect.php";

$issuetitle = $_GET['issuetitle'];

$datesubmitted = $_GET['datesubmitted'];

$systemaffected = $_GET['systemaffected'];

$prioritylevel = $_GET['prioritylevel'];

$issuedetails = $_GET['issuedetails'];

$supportcomments = $_GET['supportcomments'];

$clientFname = $_GET['clientname'];

$clientSurname = $_GET['clientSurname'];

$teamname = $_GET['teamname'];

$empName = $_GET['empName'];

$clientID = $_GET['clientID'];

$employeeID = $_GET['employeeID'];

 

$query = "insert into ClientForm values ('','".$issuetitle."','".$datesubmitted."','".$systemaffected."','".$prioritylevel."','".$issuedetails."', '".$supportcomments."', '".$clientFname."', '".$clientSurname."','".$teamname."', '".$empName."', '".$clientID."', '".$employeeID."'  )";

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

header("Location: ClientForm.php");

exit();

?>

 

Any ideas how ?

 

Thanks

 

 

Link to comment
Share on other sites

Cheers thanks for that..

 

Yeh basically when a client logs in, i want on the form his name, teamname already filled in.

And also at the same time for the foreign keys to also be filled in the database (obviously the user shouldnt be able to see this on the system).

 

I know you have to use sessions to do this, but how to use them, im not so sure about.

 

I hope that helps.

Link to comment
Share on other sites

This is the form Table

 

issuetitle

datesubmitted

systemaffected

prioritylevel

issuedetails

supportcomments

clientFname

clientSurname

teamname

empName

clientID

employeeID

 

At the bottom are foreign keys which relate to the client table and employee table

i want to populate the form table with data including the foreign keys but my problem is trying to get the data for the client whose logged in into the form table.

im wanting an autofill for the clientFname, clientSurname, clientID, employeeID of the details of the person whose logged in.

 

Any clearer ?

Link to comment
Share on other sites

Well when the user logs in you appear to be creating a session call Username

 

  $_SESSION['username'] = $row['username'];

 

What you will need to do is, find out that users employeeID and client ID by searching your database, you should beable to search for these deatils using $SESSION['username']. This means your username should be unique for every user. You can do this before your update script. Then set the clientID and employeeID to a variable and just update those feiled in your update script.

Link to comment
Share on other sites

You already know how to search a database, The will search the database on your session.

 

$query = "select * from table_name where username=$SESSION['username']

  $result = mysql_query($query, $connection) or die ("Unable to perform query
$query".mysql_error());

while($row = mysql_fetch_array($result))
{
$clientid=$row['ClientID']//this is the name of the column holding the clientid
$employeeid=$row['EmployeeID']//this is the name of the column holding the employeeid
}

Link to comment
Share on other sites

so if i wanted the same for clientFname, clientSurname, teamname, would i do the same, so it would like this.

 

<?php

session_start();

require "connect.php";

$username = $_GET['username'];

$password = $_GET['password'];

$query = "select * from client where username='".$username."' AND password='".$password."'";

 

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

 

$row=mysql_fetch_array($result);

{

$clientid=$row['clientID']

$clientFname=$row['clientFname']

$clientSurname=$row['clientSurname']

$teamname=$row['teamname']

}

 

Link to comment
Share on other sites

Yeah that will get the information and store it in a variable. The in your form you will have something like this

 

<form>
First name: 
<input type="text" name="firstname" value = <?php echo $clientFname;?>>
<br>
Last name: 
<input type="text" name="lastname" value = <?php echo $clientSurname;?>>>
</form>

Link to comment
Share on other sites

This is my code

 

<?php

session_start();

require "connect.php";

$username = $_GET['username'];

$password = $_GET['password'];

$query = "select * from client where username='".$username."' AND password='".$password."'";

 

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

 

$row=mysql_fetch_array($result);

{

$clientid=$row['clientID']

$clientFname=$row['clientFname']

    $clientSurname=$row['clientSurname']

    $teamname=$row['teamname']

}

 

if($row != null)

{

$_SESSION['username'] = $row['username'];

header("Location: ClientForm.php");

exit();

}

else

{

$message = "Invalid UserName or Password, Please Try Again";

header("Location: ClientLogin.php?message=$message");

exit();

}

?>

 

 

And this is the error message, cant work out wots wrong

 

 

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\HelpDesk\ClientLoginCheck.php on line 13

 

 

Any ideas ?

Link to comment
Share on other sites

should be

 

<?php
   session_start();
   require "connect.php";
   $username = $_GET['username'];
   $password = $_GET['password'];
   $query = "select * from client where username='".$username."' AND password='".$password."'";

   $result = mysql_query($query, $connection) or die ("Unable to perform query
$query");

   $row=mysql_fetch_array($result);
   {
   $clientid=$row['clientID'];
   $clientFname=$row['clientFname'];
    $clientSurname=$row['clientSurname'];
    $teamname=$row['teamname'];
   }

   if($row != null)
   {
      $_SESSION['username'] = $row['username'];
      header("Location: ClientForm.php");
      exit();
   }
   else 
   {
      $message = "Invalid UserName or Password, Please Try Again";
      header("Location: ClientLogin.php?message=$message");
      exit();
   }
?>

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.