简体   繁体   中英

pulling data from multiple tables on the same page

I'm stuck on this code and can't figure out where I need to go. I'm trying to pull name, phone number and email from table "contacts" which is dispayed on page and on the same page post notes to table "contactnotes" and then display them under the textbox. I can't figure out how to do it all on the same page. Here is what I have thus far.

 <?php
 mysql_connect ("link","db","pw") or die ('Error: ' .mysql_error());
 mysql_select_db ("db");

 $ID = $_GET['ID'];
 $notes = $_POST['notes'];

 $query="INSERT INTO contactnotes (id, notes)VALUES ('NULL', '".$notes."')";

 mysql_query($query) or die ('Error Updating Database');


 $sql = "SELECT * FROM contacts WHERE ID='$ID' limit 1" or die ('Error: ' .mysql_error());
 $result = mysql_query($sql) or die ('Error: ' .mysql_error());

 while ($row = mysql_fetch_array($result);

 ?>

 <!-- CONTACT INFO -->
 <div id="contact-table"><?php include("contact-info.php"); ?></div>
 <br />
 <form method="post" action="/db/notes.php?ID=<? echo $row['ID']; ?>"/>
 <input type="hidden" value="<? echo $row['id']; ?>" name = "id" id="id"/>  
 <br />

 <input type="submit" value="Edit Contact">
 <input type="submit" value="Delete Contact">
 <br />
 <br />
 <hr />
 <table border="0" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
 <tr>
 <td><strong>Notes</strong></td>
 </tr>
 <tr>  
 <td><textarea name="notes" id="notes" rows="5" cols="100"></textarea></td>
 </tr>
 </table>
 <br />
 <hr/>
 <br />
 <table width="950" border="0" cellspacing="0" cellpadding="3">
 <tr>
 <td align="left" width="100%"><h5><strong><? echo $row['user']; ?> on <? echo date("F d Y @ h:i:s", strtotime($row['timestamp'])); ?> wrote:</strong></h5></td>
 </tr>
 <tr>
 <br />
 <td align="left" width="100%"><? echo $row['notes']; ?></td>
 </tr>
 </table>
 <hr/>
 <br />
 <input type="submit" value="Edit Contact">
 <input type="submit" value="Delete Contact">
 </form>
 <?
 mysql_close();
 ?>

查看MySQL JOIN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM