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

The Archive Base Latest Questions

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

I am trying to update a data in a table which has 5 fields.

  • 0

I am trying to update a data in a table which has 5 fields.
The fields are the following: proj_name, cust_name, address, cost and details.

Here is my code for the update (update_orde.php):

 <?php
 include("connect.php");
 // get value of id that sent from address bar
 $id=$_GET['id'];
 // Retrieve data from database
 $sql="SELECT * FROM project WHERE id='$id'";
 $result=mysql_query($sql);

 $rows=mysql_fetch_array($result);
 ?>
 <table width="400" border="0" cellspacing="1" cellpadding="0">
 <tr>
 <form name="form1" method="post" action="update_orde_suc.php">
 <td>
 <table width="100%" border="0" cellspacing="1" cellpadding="0">
 <tr>

 <td colspan="5"><strong>Update Data</strong> </td>
 </tr>
 <tr>
 <td align="center"><strong>Project Name</strong></td>
 <td align="center"><strong>Customer</strong></td>
 <td align="center"><strong>Address</strong></td>
 <td align="center"><strong>Cost</strong></td>
 <td align="center"><strong>Details</strong></td>
 </tr>
 <tr>
 <td><input name="pn" type="text" id="pn" value="<? echo $rows['proj_name']; ?>"></td>
 <td align="center"><input name="cn" type="text" id="cn" value="<? echo $rows['cust_name']; ?>" size="15"></td>
 <td align="center"><input name="add" type="text" id="add" value="<? echo $rows['address']; ?>" size="15"></td>
 <td><input name="cost" type="text" id="cost" value="<? echo $rows['cost']; ?>" size="15"></td>
 <td><input name="details" type="text" id="details" value="<? echo $rows['details']; ?>" size="15"></td>
 </tr>
 <tr>
 <td align="center" colspan="5"><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">  <input type="submit" name="Submit" value="Submit"></td>
 </tr>
 </table>
 </td>
 </form>
 </tr>
 </table>


 <?

 // close connection
 mysql_close();

 ?>

and here’s the successful insertion into the database (update_orde_suc.php):

<?php
include("connect.php");
$id=$_POST['id'];
$pn = $_POST['proj_name'];
$cn = $_POST['cust_name'];
$add = $_POST['address'];
$cost = $_POST['cost'];
$det = $_POST['details'];

// update data in mysql database
$sql="UPDATE project SET proj_name='$pn', cust_name='$cn',address='$add', cost='$cost', details='$det' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='orders_edit.php'>View result</a>";
}

else {
echo "ERROR";
}

?>

The problem is that when I try to change the data there is an error that says the 3 first indexes of update_orde_suc.php are undefined (cost and details are ok).

The weirdest thing is that I used the exact same code for another table update and it worked just fine, the only thing i did now was to change the names of the variables to correspond to the names of the new table.

  • 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-04T15:39:18+00:00Added an answer on June 4, 2026 at 3:39 pm

    You mixed up the variables badly. For example you save the proj_name coming from input as $pn and later when you are inserting it in the database you use $proj_name. You have to stick with the variable names throughout the code to work.

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

Sidebar

Related Questions

I am trying to update my table t1 which has rows as following :-
I am trying to update rows in a data table that intersect rows in
I am trying to update table A with data from table B. I thought
I am trying to update a field in a table with data from another
I'm trying to pass a data table to a stored procedure. The table has
I'm trying to insert some data into a table from a csv document which
I have a table that has a about 15 different fields, some of which
I am trying update text views while this loop is processing. Here is my
When trying to update a subversion working copy from Netbeans, I get the following
Im trying to update the contents of an element after running some php code.

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.