Jump to content

Copy Record Help Please


dt_gry

Recommended Posts

$Active_tbl     =	'ActiveUsers';
$Log_tbl		=	'ActivityLog';
// connect to the mysql database server.
$connect = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$add_info = "INSERT INTO $Log_tbl ('Uname','CurDate','StartTm','EndTm','IPadd')
			SELECT * FROM $Active_tbl ('Uname','CurDate','StartTm','$EndTm','IPadd')
			WHERE $Active_tbl.Uname ='$UserID'"; 	

 

Is this correct it doesn't error out on me, however the data is not passed to $Log_tbl.

 

Thanks

dt_gry

Link to comment
Share on other sites

You need to call the query. All you've done is define a string.

 

mysql_query($add_info) or die(mysql_error());

 

Now you'll see a syntax error message.

 

 

 

$add_info = "INSERT INTO $Log_tbl ('Uname','CurDate','StartTm','EndTm','IPadd')
            SELECT Uname,CurDate,StartTm,EndTm,IPadd FROM $Active_tbl
            WHERE $Active_tbl.Uname ='$UserID'";

 

Link to comment
Share on other sites

Ok now I am getting an error I will also include my full code

 

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 ''Uname','CurDate','StartTm','06:38:30','IPadd') SELECT Uname,CurDa' at line 1

 

<?php

// set database connection information.
// $host - the mysql server address.
// $user - the username to access database.
// $pass - the password to access database.
// $database - the name of the database that is desired.
// $table - the name of the desired table.
// $CurDate - gets and stores the current date
// $StartTm - gets and stores the current time
// $IPadd - gets and stores the ip address of the client computer.

// Gets required user data
$CurDate = date('m-d-y');
$EndTm = date('H:i:s');
$IPadd = $_SERVER['REMOTE_ADDR'];

$UserID;
require_once('get_cookie.php');
// Database connection info
$host		    =	'mysql.*********.com';
$user		    =	'**********';
$pass		    =	'*********';
$database 	    =	'useractivity_tgwse';
$Active_tbl     =	'ActiveUsers';
$Log_tbl	    =	'ActivityLog';
// connect to the mysql database server.
$connect = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$add_info = "INSERT INTO $Log_tbl ('Uname','CurDate','StartTm','$EndTm','IPadd')
     	        SELECT Uname,CurDate,StartTm,EndTm,IPadd FROM $Active_tbl
         	    WHERE $Active_tbl.Uname ='$UserID'";
mysql_query($add_info) or die(mysql_error());
echo $add_info;
mysql_close($connect);
?>

 

Any Ideas guys, thanks for the help.

dt_gry

Link to comment
Share on other sites

I'm confused... to use INSERT INTO... SELECT, you need to specify the column names for the insert table -- so (a) they shouldn't be quoted and (b) it can't possibly make sense to use variables here.  My guess is you want:

 

$add_info = "INSERT INTO $Log_tbl ( Uname,CurDate,StartTm,EndTm,IPadd )

                SELECT Uname,CurDate,StartTm,'$EndTm',IPadd FROM $Active_tbl

                WHERE $Active_tbl.Uname ='$UserID'";

Link to comment
Share on other sites

  My guess is you want:

 

$add_info = "INSERT INTO $Log_tbl ( Uname,CurDate,StartTm,EndTm,IPadd )

                SELECT Uname,CurDate,StartTm,'$EndTm',IPadd FROM $Active_tbl

                WHERE $Active_tbl.Uname ='$UserID'";

 

Which is very much like the query I gave him in my post

Link to comment
Share on other sites

I was echoing it to make sure it was collecting the values and was performing the procedures. I just need to know how do I call this script from another page IE. I have 2 pages logout.php and activity.php. Activity.php is performing the above code, copying the contents from activeusers to activitylog. Thus I am wanting to call activity.php from logout.php.

 

I hope this makes sense.

thanks

dt_gry

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.