Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,926 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,801 people online right now. Registration is fast and FREE... Join Now!




Problem transferring records from one table to another

 
Reply to this topicStart new topic

Problem transferring records from one table to another

jeansymolanza
11 Mar, 2008 - 12:17 PM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
On my database I have 2 tables tbl_moderatefiles and tbl_files. I am trying to write a query that will move the a record from tbl_moderatefiles to tbl_files. Below is my current code:

CODE


<?
//connect to database//
$db_name = "ilovephysics";
$connection = @mysql_connect("localhost","jeansy","molanza123") or die(mysql_error());
$db= @mysql_select_db($db_name,$connection) or die(mysql_error());

$id=$_GET['ID'];

//assign a SQL query text to a variable//
$sql="SELECT * FROM tbl_moderatefiles WHERE ID=$id";

//run the query//
$result = @mysql_query($sql) or die(mysql_error());

//count number of rows in output//
$numrows = mysql_numrows($result);

//each time the loop executes, assign a value from the database to variables//
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$title=mysql_result($result,$i,"title");
$category=mysql_result($result,$i,"category");
$description=mysql_result($result,$i,"description");
$name=mysql_result($result,$i,"name");
$type=mysql_result($result,$i,"type");
$size=mysql_result($result,$i,"size");
$content=mysql_result($result,$i,"content");

$sql2="INSERT INTO tbl_files (date, time, title, category, description, name, type, size, content),
VALUES ('$date', '$time', '$title', '$category', '$description', '$name', '$type', '$size', '$content')";

//run the query//
$result2 = @mysql_query($sql2) or die(mysql_error());
?>



But evertime I run the code I get the error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' VALUES ('2008/03/11', '19:15:49', 'Test', 'Acoustics', 'Testing', 'cursor_hand' at line 1".

Why can't anything in PHP be simple lol?

Thanks in advance.

This post has been edited by jeansymolanza: 11 Mar, 2008 - 12:18 PM
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Problem Transferring Records From One Table To Another
11 Mar, 2008 - 02:00 PM
Post #2

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
At first glance, nothing appears wrong. But you are doing your My_SQL weird, with variables and such. Perhaps that has something to do with it, try going:

CODE
$result2 = @mysql_query("$sql2") or die(mysql_error());


Because right now your mysql_querey isn't quoted.
User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: Problem Transferring Records From One Table To Another
13 Mar, 2008 - 09:24 AM
Post #3

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
Thanks. Its working now.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:23PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month