breakthrough: get record, insert on different table works

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



it ain't pretty, but it's like a sugar rush!  Finally, able to enter data on
forms which I can create :)

[root@localhost ~]# 
[root@localhost ~]# cat /var/www/html/contacts.php -n
     1  <html>
     2  <head><title>contacts</title></head>
     3  <body>
     4  <?php
     5          $user="feeds";
     6          $host="localhost";
     7          $password="password";
     8          $database = "feeds";
     9          
    10          $connection = mysql_connect($host,$user,$password)
    11                  or die ("couldn't connect to server");
    12          $db = mysql_select_db($database,$connection)
    13                  or die ("Couldn't select database");
    14          
    15          $query = "SELECT id, link, title, content FROM px_items WHERE
feed_id=1 ORDER BY id";
    16          $result = mysql_query($query)
    17          or die ("Couldn't execute query.");
    18  ?>
    19       
    20          <form action="process.php" method="post">
    21          <select name="id">
    22
    23  <?php
    24          while($nt=mysql_fetch_array($result))
    25                  echo '<option value="'.$nt['id'].'">'.$nt['id'].'</option>';
    26  ?>
    27
    28          </select>
    29          <input type="submit" value="SEND"/>
    30          </form>
    31
    32  </body>
    33  </html> 
[root@localhost ~]# 
[root@localhost ~]# cat /var/www/html/process.php -n
     1  <html>
     2  <head><title>contacts</title></head>
     3  <body>
     4  <?php
     5
     6          error_reporting(E_ALL);
     7
     8          $user="feeds";
     9          $host="localhost";
    10          $password="password";
    11          $database = "feeds";
    12          $connection = mysql_connect($host,$user,$password)
    13                  or die ("couldn't connect to server");
    14          $db = mysql_select_db($database,$connection)
    15                  or die ("Couldn't select database");
    16
    17          foreach ($_POST as $key => $value)
    18          {
    19  //              echo "$key, $value <br><br>";
    20                  $record=$value;
    21          }//foreach
    22
    23
    24  //      echo "<br> get record ";
    25  //      echo "$record";
    26  //      echo "<br><br>";
    27
    28          $query = "SELECT id, link, title, content FROM px_items WHERE
id='$record' ORDER BY id";
    29          $result = mysql_query($query)
    30                  or die ("Couldn't execute query.");
    31
    32          $result = mysql_query($query); if (!$result) { echo
$query.'<br>'.mysql_error(); exit(1); }
    33
    34
    35  //      print_r($result);
    36
    37
    38          while ($row = mysql_fetch_array($result)) 
    39          {
    40                  extract ($row);
    41                  echo $id;
    42                  echo "<br><br>";
    43                  echo $title;
    44          }//while
    45
    46
    47          echo "<form action='insertContacts.php' method='post'>";
    48          echo "<input type='text'        name='contacts'>";
    49          echo "<input type='hidden'      name='recordID'        
value=$record>";
    50          echo "<input type='submit'                             
value='SEND'>";
    51          echo "</form>\n";
    52
    53  ?>
    54   </body> </html> 
[root@localhost ~]# 
[root@localhost ~]# cat /var/www/html/insertContacts.php -n
     1  <html>
     2  <head><title>insert contacts</title></head>
     3  <body>
     4  <?php
     5
     6          $user="feeds";
     7          $host="localhost";
     8          $password="password";
     9          $database = "feeds";
    10          $connection = mysql_connect($host,$user,$password)
    11                  or die ("couldn't connect to server");
    12          $db = mysql_select_db($database,$connection)
    13                  or die ("Couldn't select database");
    14
    15          foreach ($_POST as $key => $value)
    16          {
    17                  echo "$key, $value <br><br>";
    18                  $record=$value;
    19                  $contactData=$key;
    20          }//foreach
    21          
    22
    23          echo "recordID  ";
    24          echo $_POST[recordID];
    25          echo "<br> contacts";
    26          echo $_POST[contacts];
    27          echo "<br>";
    28
    29          $query = "INSERT INTO contacts (id , notes) VALUES
('$_POST[recordID]' , '$_POST[contacts]')";
    30          $result = mysql_query($query)
    31                  or die ("Couldn't execute query.");
    32
    33  ?>
    34   </body> </html> 
[root@localhost ~]# 
[root@localhost ~]# date
Wed Apr 25 00:06:59 BST 2007
[root@localhost ~]# 
[root@localhost ~]# 




Any thoughts/suggestions/advice as a next step?  I need to add a timestamp when
the data's entered, but that's a small thing.  This is adding notes onto
craigslist rss feeds database using <http://code.google.com/p/feed-on-feeds/>,
which is an amazing app.



-Thufir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux