SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 4th, 2003, 06:56 PM
Blair Blair is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Blair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Copying records between MySQL tables

PHP 4.3.1.1
MySQL 2.5.2
Windows XP

Main problem: I have a list of suggested links and plan to access the page that holds them to check if they should be included or not. I have a button next to each link (eventually) allowing me to either "ADD" them or "DELETE" them to the main links table from the temporary links table. When clicking add, I want to select that specific link and save the entire record into the main links table; likewise for the delete button. The code I have so far is:

php Code:
Original - php Code
  1.  
  2.         include "format/connect.php";
  3.         if (!$db) {
  4.         die( '<p>Unable to connect to the database server at this time.</p>' );
  5.         }
  6.         if (! @mysql_select_db('westerlands') ) {
  7.         die( '<p>Unable to locate the Westerlands database at this time.</p>' );
  8.         }
  9.         //add
  10.         if (isset($_POST['add_suggested_link'])) {
  11.         $unique = $_POST['unique'];
  12.         $sql = "INSERT INTO urls ($name, $url, $id, $description, $email ) VALUES name, url, id, description, email FROM temp_link WHERE $unique=unique";
  13.            
  14.         echo "<br />updated rows = ".mysql_affected_rows();
  15.         if (@mysql_query($sql)) {
  16.         echo('added');
  17.         } else {
  18.         echo('error adding suggested link');
  19.         }}
  20.         //delete
  21.         if (isset($_POST['delete_suggested_link'])) {
  22.         $unique = $_POST['unique'];
  23.         $sql = "DELETE * FROM temp_link WHERE $unique=unique";
  24.         if (@mysql_query($sql)) {
  25.         echo('deleted');
  26.         } else {
  27.         echo('error deleting suggested link');
  28.         }}


Any ideas?

Reply With Quote
  #2  
Old August 4th, 2003, 07:54 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: Copying records between MySQL tables

For starters, your insert statement isn't quite right. It should be more like:
Code:
INSERT INTO urls (name, url, id, description, email) SELECT name, url, id, description, email FROM temp_link WHERE unique='$unique'


Reply With Quote
  #3  
Old August 5th, 2003, 06:04 AM
Blair Blair is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Blair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Copying records between MySQL tables

Hi honcho,

Thanks for the feedback. Changed the sql to what you suggested but it still isn't writing the new record. I'm having a similar type of problem with another page where I am trying to update the contents of a table: the contents are displayed in form fields and the administrator should be able to alter the data and click update, but it doesn't write the new data to the table. Does this overwriting problem sound like a similar one to the LINKS problem? I have a funny feeling the MySQL server isn't quite set up correctly; does this sound likely? I've spoken to the support guys for the server and he is looking into it.

Any feedback much appreciated.

Reply With Quote
  #4  
Old August 5th, 2003, 11:18 AM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: Copying records between MySQL tables

Change the line with "echo('error adding suggested link');" to be:
php Code:
Original - php Code
  1.  
  2. echo('error adding suggested link: '.mysql_error());


That will show you the actual error mySQL is having.

Reply With Quote
  #5  
Old August 5th, 2003, 11:22 AM
Blair Blair is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Blair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Copying records between MySQL tables

Hi honcho,

This extra information might be useful if the script was actually getting as far as that line! What I'm getting when I click "ADD" is simply nothing; no action!


Reply With Quote
  #6  
Old August 5th, 2003, 12:16 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Copying records between MySQL tables

So, when you click the add button it doesn't even submit the page? It doesn't do anything? Can you sit there and click the add button multiple times and it never go away?

Can you show us the code for the add button and the form that goes with it?

Reply With Quote
  #7  
Old August 5th, 2003, 02:49 PM
Blair Blair is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 4 Blair User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Copying records between MySQL tables

Entire php code:

php Code:
Original - php Code
  1.  
  2. <?php
  3.         include "format/connect.php";
  4.         $result = mysql_query("SELECT * FROM temp_link ORDER BY tdate DESC",$db);
  5.         echo '<h3>approve links</h3>';
  6.         while ( $row = mysql_fetch_array($result) ) {
  7.         echo "<a href='".$row['url']."' target='_blank'>".$row['name']."</a><br /><span id='link_text'>".nl2br($row['description'])."<br /><em id='hit'>".$row['tdate']."</em><form><input class='button' type='submit' name='add_suggested_link' value='add' /><input type='submit' class='button' name='delete_suggested_link' value='delete' /></form><br />";
  8.               }
  9.         include "format/connect.php";
  10.         if (!$db) {
  11.         die( '<p>Unable to connect to the database server at this time.</p>' );
  12.         }
  13.         if (! @mysql_select_db('westerlands') ) {
  14.         die( '<p>Unable to locate the Westerlands database at this time.</p>' );
  15.         }
  16.         //add
  17.         if (isset($_POST['add_suggested_link'])) {
  18.         $unique = $_POST['unique'];
  19.         $sql = "INSERT INTO urls (name, url, id, description, email) SELECT name, url, id, description, email FROM temp_link WHERE unique='$unique'";
  20.         echo "<br />updated rows = ".mysql_affected_rows();
  21.         if (@mysql_query($sql)) {
  22.         echo('added');
  23.         } else {
  24.         echo('error adding suggested link: '.mysql_error());
  25.         }}
  26.         //delete
  27.         if (isset($_POST['delete_suggested_link'])) {
  28.         $unique = $_POST['unique'];
  29.         $sql = "DELETE * FROM temp_link WHERE unique='$unique'";
  30.         if (@mysql_query($sql)) {
  31.         echo('deleted');
  32.         } else {
  33.         echo('error deleting suggested link');
  34.         }}
  35. ?>

Reply With Quote
  #8  
Old August 5th, 2003, 02:59 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: Copying records between MySQL tables

php Code:
Original - php Code
  1. echo "<a href='".$row['url']."' target='_blank'>".$row['name']."</a><br /><span id='link_text'>".nl2br($row['description'])."<br /><em id='hit'>".$row['tdate']."</em><form><input class='button' type='submit' name='add_suggested_link' value='add' /><input type='submit' class='button' name='delete_suggested_link' value='delete' /></form><br />";


You aren't telling it where to go or how to do it...A form tag should look like so:

<form action="myscript.php" method="POST">

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Copying records between MySQL tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |