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 8224561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:06:42+00:00 2026-06-07T15:06:42+00:00

table: test1 ———- |id |name| ———- |46 |BOB | ———- table: test2 ———————— |id

  • 0
table: test1
----------
|id |name|
----------
|46 |BOB |
----------

table: test2
------------------------
|id  |name_id |job     |
------------------------
|133 |46      |NOJOB   |
------------------------
|134 |46      |NOJOB   |
------------------------
|135 |46      |NOJOB   |
------------------------

Hello, i have a problem to update multiple rows on the “test2.job” respectively based on the “test2.name_id which is resulted from the mysql_insert_id(); function from “test1.id” in the INSERT query and my table structure as above.

I have the form that will populated depends on how much record i have in “test2” table with a condition of “WHERE name_id = ‘”.$_GET[‘id’].”‘” and i have specified “localhost/rfps/ztransposto.php?id=46” in the browser url address and the form will shows as what is in the test2 table above.

The thing is when i try to change and update the first and the second row it will update nothing as it only will update if i change the last row value and updates the other two rows both first and second row with the same value. Below are the source code:

1-update form page

<?php require_once('Connections/rfps.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
 }
?>

<html>
<head>
</head>
<body>

<?php

$sql = "SELECT * FROM test2 WHERE name_id = '".$_GET['id']."'";

$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());

$i = 0;

echo '<table width="50%">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>Name ID</td>';
echo '<td>Job</td>';
echo '</tr>';

echo "<form name='form_update' method='post' action='ztranspostop.php'>\n";
while ($job = mysql_fetch_array($result)) {
echo '<tr>';
echo "<td>{$job['id']}<input type='hidden' name='id[$i]' value='{$job['id']}' /></td>";
echo "<td>{$job['name_id']}<input type='hidden' name='name_id[$i]' value='{$job['name_id']}' /></td>";
echo "<td><input type='text' size='40' name='job[$i]' value='{$job['job']}' /></td>";
echo '</tr>';
++$i;
}
echo '<tr>';
echo "<td><input type='submit' value='submit' /></td>";
echo '</tr>';
echo "</form>";
echo '</table>';

?>
</body>
</html>

2-update query page

<?php require_once('Connections/rfps.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

$size = count($_POST['job']);

$i = 0;
while ($i < $size) {
    $job= $_POST['job'][$i];
    $name_id = $_POST['name_id'][$i];

    $query = "UPDATE test2 SET job = '$job' WHERE name_id = '$name_id'";
    mysql_query($query) or die ("Error in query: $query");
    echo "$job<br /><br /><em>Updated!</em><br /><br />";
    ++$i;
}
?>

Can anyone point out which part of the codes i got it wrong? Thanks in advance!

  • 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-07T15:06:44+00:00Added an answer on June 7, 2026 at 3:06 pm

    I think you are missing the connection between the test2.id field in the form and using it in the update query. In fact, you probably don’t need the WHERE name_id = clause if you include the WHERE id = instead. This completes the association between a row in your form (the values of $i on that page) and the particular job row being updated (the values of $i on the subsequent page). Otherwise, you are only updating based on an attribute which they will all have in common (name_id) 🙂

    $i = 0;
    while ($i < $size) {
        $job= $_POST['job'][$i];
        $job_id = intval($_POST['id'][$i]);
    
        $query = "UPDATE test2 SET job = '$job' WHERE id = '$job_id'";
        mysql_query($query) or die ("Error in query: $query");
        echo "$job<br /><br /><em>Updated!</em><br /><br />";
        ++$i;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table: id name bid 1 Test1 5.50 2 Test2 5.50 3
I have a table with the following columns: ID Name 1 test1 2 test2
<div id=jobs> <table> <tbody> <tr id=test1> <td>TEST1</td> <td><button data-job=test1>&gt;</button></td> </tr> <tr id=test2> <td>TEST2</td> <td><button
I have a table: test(id, name1, name2) and data in table test(1, test1, test2
I have a table that looks like this: id test1 test2 test3 test4 ...
I have table data like this id id1 name 1 1 test1 1 1
here is the table and data like: id name 1 test1 2 test2 3
I've got tables like: table A id name email 1 test1 ex@ex.com 2 test2
I have a html table <table class=items> <tr> <td>test1</td> <td>test2</td> <td>test3</td> </tr> </table> I
TABLE A >> uid name 1 test1 2 test2 3 test3 4 test4 TABLE

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.