I am building a website at the moment and would like to redirect users to a page that displays the information relating to their id when they log in. I have the login script already I just cant get it to go to the right page.
We can't really help you with such generic information, but the basic strategy is this:
- Store current user info in session
- Provide a link to an edit page
- Edit page polls database info, plugs it into existing form fields
- User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.
- Store current user info in session - This I have done
- Provide a link to an edit page - This I have done
- Edit page polls database info, plugs it into existing form fields - This I don't know how to do!
- User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.
I can get the page to poll the database info and show it to the specific user but not allow them to edit it.
- Store current user info in session - This I have done
- Provide a link to an edit page - This I have done
- Edit page polls database info, plugs it into existing form fields - This I don't know how to do!
- User hits "Update" and the info gets pushed back into the database, where database table info user id = session user id.
I can get the page to poll the database info and show it to the specific user but not allow them to edit it.
Foster
Foster,
If i have understood your above requirement correctly your looking for below information else ignore.
edit page is nothing like copy your original form page in new file and name it as edit.php?edit=edit
Now select table from db as an array, using while condition echo its value in the respective input field as VALUE (Do not change the name at any cost but just add value="" to input filed) , For example check below.
do it for every input field and send back information to DB via same back end script you used while creating the record & create one if condition in back end let say if(edit=="edit") use UPDATE command else use INSERT command so, one back end script act good for create & edit data.
but only effort you need to do is updating "VALUES" as per input types in the edit.php?edit=edit page.
<font> <b>STOP!</b><br> Please check your information before pressing the submit button below. Looking over your information now will make sure editing later won't be necessary. Thank you.<BR> <input type="hidden" name="FormSubmit" value="Yes"> <INPUT TYPE="submit" value="Update Regiment"> <INPUT TYPE="reset" value="Reset Fields"> </td></tr></table>
Well I can't give you a verbatim set of directions because I don't know your database schema or what you're using to access it (Native methods, an ORM, PDO, etc), but... I've tossed in some pseudo code and removed irrelevant parts and replaced them with "..."
PHP Code:
<?php
// Inialize session
session_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['Comname'])) {
header('Location: login.html');
} else {
// Get Current User ID from $_SESSION
// query your database
// get an array/object with appropriate values
// e.g.
// $user->regiment_name = mysqlres["name"];
// $user->commander_name = mysqlres["CommanderName"];
// $user->historical = mysqlres["HistoricalFigures"];
// etc
// you've got the right idea for your Regiment Name. You won't be looping
// through a set though (with multiple rows) because you only have a single
// row returned from your query
//
// *NB* for <TEXTAREA>, you don't set the 'value' attribute, you just put the data between the open and closing tags.
}
?>
...
<div class="postcontent">
<!-- Begin Content -->
<form action="update.php" method="post">
<center>
<font>
<b>STOP!</b><br>
Please check your information before pressing the submit button below. Looking over your information now will make sure editing later won't be necessary. Thank you.<BR>
<input type="hidden" name="FormSubmit" value="Yes">
<INPUT TYPE="submit" value="Update Regiment"> <INPUT TYPE="reset" value="Reset Fields">
</td></tr></table>
I have that already it's when selecting the database that I have the problem. The code below selects ID 1 but I want it to select according the the username of the person logged in.
PHP Code:
$result = mysqli_query($con,"SELECT * FROM IGarmy WHERE id = 1");