By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,526 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,526 IT Pros & Developers. It's quick & easy.

how to update record with 2 tables?

P: 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
Share this Question
Share on Google+
1 Reply

P: 7
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

Post your reply

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