1 Replies - 832 Views - Last Post: 25 February 2009 - 06:24 AM

#1 drgnfly1007   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-May 08

Select info from one table and write to another

Posted 23 February 2009 - 03:12 PM

I have a table with event information in it and I need to take selected info and put it into another dadabase. The problem is that both tables are from separate applications and therefore use different field names for the sam e info. How can I work around this. The info is to be used in a phplist form. The form code is below.
The info is being pulled from a table called events. I need the event_id and the event_title to be written to a table called phplist_phpattr_events with the fields id , name, and list_order.


<?php require_once('../Connections/zocalo.php'); ?>
<? $con = mysql_connect("localhost","zocal0_zocalola","vazquez"); ?>

<?php
mysql_select_db($database_zocalo, $zocalo);
$query_rs_UpcomingEvents2 = "SELECT event_id, event_title, event_date, event_time, event_image, location_name, event_list FROM event WHERE event_date >= '" . date("Y-m-d") . "'AND event_list = '1' ORDER BY event_date ASC";
$rs_UpcomingEvents2 = mysql_query($query_rs_UpcomingEvents2, $zocalo) or die(mysql_error());
$row_rs_UpcomingEvents2 = mysql_fetch_assoc($rs_UpcomingEvents2);
$totalRows_rs_UpcomingEvents2 = mysql_num_rows($rs_UpcomingEvents2);
?>
<?php

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
  $updateSQL = sprintf("UPDATE event SET event_title=%s, event_subtitle=%s, event_series=%s, event_date=%s, event_time=%s, event_year=%s, location_name=%s, event_moderator=%s, event_presented=%s, event_desc=%s WHERE event_id=%s",
					   GetSQLValueString($_POST['event_title'], "text"),
					   GetSQLValueString($_POST['event_subtitle'], "text"),
					   GetSQLValueString($_POST['event_series'], "int"),
					   GetSQLValueString($_POST['event_date'], "date"),
					   GetSQLValueString($_POST['event_time'], "date"),
					   GetSQLValueString($_POST['event_year'], "date"),
					   GetSQLValueString($_POST['location_name'], "text"),
					   GetSQLValueString($_POST['event_moderatedby'], "text"),
					   GetSQLValueString($_POST['event_presented'], "text"),
						GetSQLValueString($_POST['event_desc'], "text"),
					   GetSQLValueString($_POST['event_id'], "int"));
  mysql_select_db($database_zocalo, $zocalo);
  $Result1 = mysql_query($updateSQL, $zocalo) or die(mysql_error());

}

?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!--  Created with the CoffeeCup HTML Editor 2008  -->
<!--		   http://www.coffeecup.com/		   -->
<!--		Brewed on 2/11/2009 11:28:38 AM		-->
<head>
  <title>Reserve a Seat</title>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <script language="javascript">
window.resizeTo(750,height=575);
</script>
</head>
<body background="http://www.zocalopublicsquare.org/images/bg_sendfriend2.jpg">
<table width="74%" height="119" border="0" align="center" cellpadding="0">
  <tr>
	<td height="115" align="center" valign="bottom"><p>&nbsp;</p>
	  <p><b><font color="#993333" face="Verdana, Arial, Helvetica, sans-serif">Reservation
	Request Form</font></b></p></td>
  </tr>
</table>
<form method="post" action="http://zocalopublicsquare.org/lists/?p=subscribe&id=2" name="subscribeform"> 
<!-- <input type="hidden" name="list[2]" value="signup"> -->

<table border=0>
  <tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email</font></div></td>
  <td class="attributeinput"><input type=text name=email value="" size="40">
  <script language="Javascript" type="text/javascript">addFieldToCheck("email","Email");</script>
  </td>
  </tr>
  
  <tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Confirm your email address</font></div></td>
  <td class="attributeinput"><input type=text name=emailconfirm value="" size="40">
  <script language="Javascript" type="text/javascript">addFieldToCheck("emailconfirm","Confirm your email address");</script></td></tr><input type=hidden name="htmlemail" value="1">

<tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">First Name:</font></div></td><td class="attributeinput">
			<input type=text name="attribute1"  class="attributeinput" size="40" value=""><script language="Javascript" type="text/javascript">addFieldToCheck("attribute1","First Name:");</script></td></tr>

<tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Last  Name:</font></div></td><td class="attributeinput">
			<input type=text name="attribute2"  class="attributeinput" size="40" value=""><script language="Javascript" type="text/javascript">addFieldToCheck("attribute2","Last  Name:");</script></td></tr>

<tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Phone Number:</font></div></td><td class="attributeinput">
			<input type=text name="attribute4"  class="attributeinput" size="40" value=""><script language="Javascript" type="text/javascript">addFieldToCheck("attribute4","Phone Number:");</script></td></tr>

<tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Zip:</font></div></td><td class="attributeinput">
			<input type=text name="attribute3"  class="attributeinput" size="40" value=""><script language="Javascript" type="text/javascript">addFieldToCheck("attribute3","Zip:");</script> &nbsp; &nbsp;<a href="zip.php" onclick="window.open('zip.php','nameOfWindow','width=520,height=510');return false">Why
	   We Ask?</a></td></tr>


 <TR>
   <TD ><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Event You
	   would like to Attend:</font></div></td>
   <td class="attributeinput">
   <!-- <select name="rsvp_event" id="rsvp_event"> -->
<!--

mysql_select_db($database_zocalo, $zocalo);
$query_rs_UpcomingEvents2 = "SELECT event_id, event_title, event_date, event_time, event_image, location_name, event_list FROM event WHERE event_date >= '" . date("Y-m-d") . "'AND event_list = '1' ORDER BY event_date ASC";
$rs_UpcomingEvents2 = mysql_query($query_rs_UpcomingEvents2, $zocalo) or die(mysql_error());
$row_rs_UpcomingEvents2 = mysql_fetch_assoc($rs_UpcomingEvents2);
$totalRows_rs_UpcomingEvents2 = mysql_num_rows($rs_UpcomingEvents2);

-->   
   
   <select name="attribute7" class="attributeinput">
	 <?php
do {  
?>
	 <option value="<?php echo $row_rs_UpcomingEvents2['event_title']?>
	 				<?php if (!(strcmp($row_rs_UpcomingEvents2['event_title'], $row_rs_UpcomingEvents2['event_title']))) {echo "selected=\"selected\"";} ?>">
					<?php echo $row_rs_UpcomingEvents2['event_title']?>
					 <?php
							} while ($row_rs_UpcomingEvents2 = mysql_fetch_assoc($rs_UpcomingEvents2));
							  $rows = mysql_num_rows($rs_UpcomingEvents2);
							  if($rows > 0) {
								  mysql_data_seek($rs_UpcomingEvents2, 0);
								  $row_rs_UpcomingEvents2 = mysql_fetch_assoc($rs_UpcomingEvents2);
							  }
					?> 
	</option>
   </select>
</TR>

<!--
<tr><td><div class="required">Event:</div></td><td class="attributeinput">
			<input type=text name="attribute7"  class="attributeinput" size="40" value="   ">
	<script language="Javascript" type="text/javascript">addFieldToCheck("attribute7","Event:");
</script>
</td></tr>
-->

<tr><td><div class="required"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Seats Requested: <i>Limit Four</i></font></div></td>
<td class="attributeinput"><!--0-->
<select name="attribute5" class="attributeinput">
<option value="1" >1<option value="2" >2<option value="3" >3<option value="4" >4
</select>
</td></tr>

<tr>
<td colspan="2">
<br />

<input type="hidden" name="list[3]" value="signup"><input type="hidden" name="listname[3]" value="RSVP"/><div style="display:none"><input type="text" name="VerificationCodeX" value="" size="20"></div><input type=submit name="subscribe" value="Submit RSVP Request" onclick="return checkform();">
<div align="center">
	   <br><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">All
		 programs are free and open to the public. </font><br>
	   <font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Seating
		   is limited; reservations are recommended. All reservations will be
		   confirmed via return e-mail. </font><br>
	   <font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>We
		 cannot confirm your reservation without a correct email address.</strong></font><br>
	 </div>
</td>
</tr>
</table>
	</form>
	<table>
	   <TR>
	 <TD colspan="3"></TD>
	</TR>
</table>
</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: Select info from one table and write to another

#2 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: Select info from one table and write to another

Posted 25 February 2009 - 06:24 AM

You just need to specify the fieldnames. as long as the types do not give a problem, it should work.
insert into x (fieldA, fieldB, fieldC) select field1, field2, field3 from y where somecondition
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1