473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

how to update record with 2 tables?

29
i have 2 tables,
1. account
-id,
-accounttypeid,
-name

2. accounttype
-accounttypeid,
-type.

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

Expand|Select|Wrap|Line Numbers
  1. <html><head></head>
  2. <body>
  3. <?php
  4. $jenis =$_POST['accounttypeid'];
  5.  
  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.         <?
  15.  
  16. if (isset ($_POST['submit'])) {
  17.  
  18.    $name = $_POST['name'];
  19.    $sid = $_POST['accounttypeid'];
  20.    $ID=$_GET['ID'];
  21.  
  22.  
  23.       $updatelink="Update account set name='$name', accounttypeid ='$sid'";
  24.       mysql_query($updatelink) or die(mysql_error());
  25.       print "Link updated.";
  26.  
  27. } else
  28. {
  29.  
  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);
  34.  
  35.  
  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>
  44.  
  45.  
  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>
  52.  
  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 2008
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

5
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'...
8
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 ...
16
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...
5
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...
1
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...
3
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...
3
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...
15
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...
2
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
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,...
0
isladogs
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...

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.