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

  • Home
  • SEARCH
  • 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 7971547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:39:44+00:00 2026-06-04T07:39:44+00:00

How do I insert a table entry in my messages table for each user.ID

  • 0

How do I insert a table entry in my messages table for each user.ID where the users.MM_Division = division.divisionid

I want to insert the user ID value in the messages.messagesuserid

I think I need a while loop but I’m not sure how I implement it when dealing with a insert query.

Currently, only 1 message row is inserted into the messages table on the messageuserid value posts as NULL

Thanks

Here’s my code:

session_start();

$colname_division = "-1";
if ((isset($_GET['divisionid'])) && ($_GET['divisionid'] != "")) {
      $colname_division = $_GET['divisionid'];

mysql_select_db($database_connect, $connect);
$query_users = sprintf("SELECT users.*, division.* FROM users INNER JOIN division ON division.divisionid = users.MM_Division WHERE divisionid = %s", GetSQLValueString($colname_users, "int"));
$users = mysql_query($query_users, $connect) or die(mysql_error());
$row_users = mysql_fetch_assoc($users);
$totalRows_users = mysql_num_rows($users);


// MESSAGE USERS DIVISION ARCHIVED
    $messageinsertSQL = sprintf("INSERT INTO messages (message, messageuserid) VALUES ('The division " . $row_division['division'] . " has been archived by " . $_SESSION['MM_Username'] . " please select a new division', '" . $row_users['ID'] . "')",GetSQLValueString($_GET['divisionid'], "int")); 
    mysql_select_db($database_connect, $connect);
    $Result4 = mysql_query($messageinsertSQL, $connect) or die(mysql_error());


// REDIRECT
    $updateGoTo = "../divisions.php";
        if (isset($_SERVER['QUERY_STRING'])) {
            $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
            $updateGoTo .= $_SERVER['QUERY_STRING'];
        }
    header(sprintf("Location: %s", $updateGoTo));

    mysql_free_result($division);
    exit;
}
  • 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-04T07:39:45+00:00Added an answer on June 4, 2026 at 7:39 am

    Wrap that message users division archived part with:

    while (($row_users = mysql_fetch_assoc($users)) !== false) {
     $messageInsert = ...
     [...]
    }
    

    Then you need to remove $row_users = mysql_fetch_assoc($users) used earlier.

    BTW, I’m not sure if some columns won’t get overwritten if they have the same names (from users and divisions) in $query_users = line.
    Besides, that line has wrong parameter $colname_users in GetSQLValueString() function (shouldn’t it be $colname_division? Or do you declare it somewhere else?).

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

Sidebar

Related Questions

INSERT INTO table is producing a NULL value for the returned recordset. I'm trying
I can't get table entry index. I need it to remove an item from
I have a table in SQL Server with an entry that came from: INSERT
I have this query where I want to insert into table exp_channel_data data from
DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
is it possible to insert a table row that doesn't adhere to any columns?
It is possible to insert multiple rows like this: INSERT INTO table VALUES (...),
What is main difference between INSERT INTO table VALUES .. and INSERT INTO table
I'm running a pretty standard INSERT INTO [table] (col1, col2, ...coln) select * from
I have the following query: INSERT INTO table (a, b, c) VALUES (NOW(), NOW()

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.