Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:12:18+00:00 2026-06-17T13:12:18+00:00

I followed the register & login series from PHPAcademy and I built a login

  • 0

I followed the register & login series from PHPAcademy and I built a login system. I wanted to add an announcement system to it. I have built that, but I am not able to store the first name and last name of the user logged-in in the table. The message and dates are getting inserted but the not the userdata.

The user details like name, sex, dept all are stored in other table but I want only two fields – first name and last name, so I thought of using session variables. Also, I am weak in that JOIN concept, can anyone please explain me, I have a strange feeling it can be done using that but I don’t know how, I tried two times but failed (maybe because I don’t get the concept)

Please help. Here are the codes:

    <?php
    include $_SERVER["DOCUMENT_ROOT"].'/TestSite/core/init.php';
    faculty_protect_page();
    include $_SERVER["DOCUMENT_ROOT"].'/TestSite/includes/overall/header.php';

    if(empty($_POST)===false) {
        $required_fields = array('announce');
        foreach($_POST as $key=>$value) {
            if(empty($value) && in_array($key, $required_fields) === true ) {
                $errors[] = 'It seems like you have not made any announcement!';
                break 1;
            }
        }
        if(empty($errors) === true ){
            if(strlen($_POST['announce']) < 20) {
                $errors[] = 'Your announcement must be atleast 20 characters long!';
            }
            if(strlen($_POST['announce']) > 250) {
                $errors[] = 'Your announcement cannot be more than 250 characters long!';
            }
        }
    }
?>
<center><h3>Make an announcement</h3></center>
<?php
                if(isset($_GET['success'])===true && empty($_GET['success'])===true) {
                    echo 'You have successfully made an announcement';
                }
                else {
                    if(empty($_POST)=== false && empty($errors)===true) {
                        $announcement = array(
                            'announce'     => $_POST['announce'],
                       //'faculty_fname' => $_SERVER['faculty_fname'] this didn't work
                            );
                        announce($announcement);
                        header('Location: announce.php?success');
                        exit();
                    }
                    else if(empty($errors)===false) {
                        echo output_errors($errors);
                    }

    ?>
    <form action="" method="POST">
        <br/>
        <input type="text" class="span12" name="announce" maxlength="250"/><br/><br/>
        <center><input type="submit" class="btn btn" value="Announce" /></center>     
    </form>
<?php
}
include $_SERVER["DOCUMENT_ROOT"].'/TestSite/includes/overall/footer.php'; ?>

Here is my announce function placed in a functions file (required by init.php):

    function announce($announcement) {
        array_walk($announcement, 'array_sanitize');
        $announcement['announce'] = ucfirst($announcement['announce']);
        $fields = '`' . implode('`, `', array_keys($announcement)) . '`';
        $data = '\'' . implode('\', \'', $announcement) . '\'';
        $one = $_SESSION['faculty_fname'];        
        mysql_query("INSERT INTO `notices` ($fields, `faculty_fname`, `datetime`) VALUES ($data, '$one', NOW())");
    }

Can anyone please help me inserting the first name of faculty in the table? I have spent one whole day on this and couldn’t succeed.

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:12:19+00:00Added an answer on June 17, 2026 at 1:12 pm

    If you want to store the user information in the notices record, you want to store for example the primary key from the user table that corresponds to the user who is announcing the notice.
    Your notices table will have to have a user_id column and the id’s that will be stored in this column are often referred to as foreign keys. In this way you are not storing duplicate information in your database. All the user specific information is already stored in the user_table, so there is no need to store it again in the notices table, just a means to connect a user to a notice.

    To work this into your current code you might do something along the lines of the following.

    1. When you want to insert a new notice in the notices table you first need to retrieve the user record from the database for the person that is submitting the notice. How you do this depends on how your login system is built, but for example, on login you could store the primary key from the user in the session. On notice submit, you retrieve the user id from the session and use it to query the database. In semi-pseudocode:

      $mysqli = new mysqli("localhost", "root", "", "");
      $user_id = $_SESSION['user_id'];  
      $sql = $mysqli->prepare("SELECT * FROM user_table WHERE user_id = ?");  
      $sql->bind_param("i", $user_id); 
      
    2. Now that we have the record of the logged in user you can insert the notice in the notices table

      $notice = $_POST['notice'];  
      $user_id = $_SESSION['user_id'];  
      $sql = $mysqli->prepare("INSERT INTO notices ('notice', 'user', 'datetime') VALUES (?,?,NOW())");  
      $sql->bind_param("si", $notice, $user_id);
      

    After you execute the query, the new record contains the user_id in the user column of table notices that corresponds to the primary key in the user_table where all the user spec ific information can be found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed the Railcast #270 has_secure_password tutorial and have that all working. For
I followed the basic steps to add authentication to Rails using Devise from their
Am attempting to add push notifications to an application that I have created. I
I've followed the instruction from Adding custom attributes to an element in XAML? but
I have followed the code here - > https://github.com/jaredhanson/passport-local/tree/master/examples/express3 for add local authentication for
I have a JSF page with a few fields. I followed this tutorial from
I wanted to add an action on Sales>Order in Magento admin. Screenshot- I followed
I'm fairly new to COM programming and I have a DLL that compiles, but
I wanted to have a Visual Studio package that is loadable in VS2008. To
I have been trying to register 3 hotkeys. I followed this example (or this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.