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
https://forums.phpfreaks.com/topic/128324-copy-record-help-please/
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'";

 

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

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'";

  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

Okay, actually I spoke too soon, echo gives me the correct values that should be in the table from what I am using as a test, however it doesnt copy to ActivityLog table and doesnt delete.

 

Any suggestions.

 

Thanks Again

dt_gry

 

What, exactly, does this line output

echo $add_info;

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.