473,699 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to update record with 2 tables?

29 New Member
i have 2 tables,
1. account

2. accounttype

i can add record by join the table,
but if i need update record, it cant,
can some 1 help me?
how to update?

Expand|Select|Wrap|Line Numbers
  1. <html><head></head>
  2. <body>
  3. <?php
  4. $jenis =$_POST['accounttypeid'];
  6. $connect =mysql_connect("localhost","root","") or die (mysql_error());
  7. $select = mysql_select_db("phplogin") or die (mysql_error());
  8.    $q = mysql_query("select * from accounttype");
  9.         while ($row = mysql_fetch_assoc($q)) 
  10.         {
  11.                 $jenis .= "<option value = $row[accounttypeid]>$row[type]";
  12.         }
  13.         ?>
  14.         <?
  16. if (isset ($_POST['submit'])) {
  18.    $name = $_POST['name'];
  19.    $sid = $_POST['accounttypeid'];
  20.    $ID=$_GET['ID'];
  23.       $updatelink="Update account set name='$name', accounttypeid ='$sid'";
  24.       mysql_query($updatelink) or die(mysql_error());
  25.       print "Link updated.";
  27. } else
  28. {
  30.    $ID=$_GET['ID']; //gets the id from URL
  31.    $sql="SELECT account.id, account.name, accounttype.type from account, accounttype where account.accounttypeid = accounttype.accounttypeid and account.id='$ID'";
  32.    $result=mysql_query($sql) or die("Could not get button"); 
  33.    $row=mysql_fetch_array($result);
  36.    ?>
  37.    <form method="post" action="lista.php" >
  38.    <table><tr><td><input type="hidden" name="ID" value="$ID"></td></tr><tr><td>Name: </td> <td><input name="name" type="text" id="name" value="<? echo $row['name']; ?>"></td></tr>
  39.    <tr><td>
  40.      Accounttype: </td> <td><select name="accounttypeid"><?php print ($jenis); ?>
  41. </select></td></tr>
  42.    <tr><td colspan="2"> <input type='submit' name="submit"  value='submit'></td></tr>
  43.    </table></form>
  46. <? }
  47. ?>
  48. <form method="post" action="viewa.php">
  49. <table><tr><td>
  50. <input type="submit" name="view" value="View">
  51. </td></tr></table></form>
  53. <form method="post" action="a6.php">
  54. <table>
  55. <tr><td>
  56. <input type="submit" name="back" value="Back">
  57. </td></tr></table></form>
  58. </body></html>
Sep 14 '09 #1
1 2023
7 New Member
I gather you are asking for assistance creating an UPDATE query across multiple tables?

Expand|Select|Wrap|Line Numbers
  1. UPDATE tableName t1 JOIN tableName t2 ON t1.field = t2.field SET t1.field = 'value', t2.field = 'value', etc. WHERE t1.field = 'value' AND t2.field = 'value';
Sep 15 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: jayson_13 | last post by:
Hi, I need to implement a counter and i face problem of locking so hope that u guys can help me. I try to do test like this : 1st connection SELECT * FROM nextkey WHERE tblname = 'PLCN' FOR Update; (when i execute this statement and i guess that this will lock the
by: Jan van Veldhuizen | last post by:
The UPDATE table FROM syntax is not supported by Oracle. I am looking for a syntax that is understood by both Oracle and SqlServer. Example: Table1: id name city city_id 1 john newyork null
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
by: jpr | last post by:
Hello, I know that this is not the rule but need some help. My datbase has three tables: MASTER TEMPLATES FORMS I have a form which is based on a table named MASTER. I have a primary key set to autonumber and a field SSN which I would
by: Roy | last post by:
Hi Access gurus, I have a A2K application.The data in the database is updated daily by a excel download.I have a master n related tables keyed in by a OrderID.I have a problem in updating data.If it is a one to one update,i face no problem as I update every fields.But let's say if there is a master record with ID and three corresponding related entries for this on day 1.But on the next day,there was a change on related records 2 & 3 but...
by: Scotty | last post by:
I like to have a good insert, update and delete code The code below sometimes workl ok sometimes doesnt work, what i am doing wrong?? Sub SaveAny() Dim command_builder As New OleDb.OleDbCommandBuilder(daOrders) ' Save any changes.
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.