dt_gry Posted October 14, 2008 Share Posted October 14, 2008 $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 Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/ Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-664759 Share on other sites More sharing options...
dt_gry Posted October 14, 2008 Author Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-664918 Share on other sites More sharing options...
fenway Posted October 14, 2008 Share Posted October 14, 2008 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-664947 Share on other sites More sharing options...
dt_gry Posted October 14, 2008 Author Share Posted October 14, 2008 Thanks fenway, worked like a charm. dt_gry Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-664960 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665040 Share on other sites More sharing options...
dt_gry Posted October 14, 2008 Author Share Posted October 14, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665204 Share on other sites More sharing options...
fenway Posted October 14, 2008 Share Posted October 14, 2008 I don't understand. Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665283 Share on other sites More sharing options...
dt_gry Posted October 14, 2008 Author Share Posted October 14, 2008 Okay if I am going to call this from another page to process this information ie. logout.php would the statement be <?php include('recordactivity.php') ?>. Thanks dt_gry Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665345 Share on other sites More sharing options...
fenway Posted October 14, 2008 Share Posted October 14, 2008 I'm still lost. Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665536 Share on other sites More sharing options...
Barand Posted October 14, 2008 Share Posted October 14, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665547 Share on other sites More sharing options...
dt_gry Posted October 15, 2008 Author Share Posted October 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665786 Share on other sites More sharing options...
Barand Posted October 15, 2008 Share Posted October 15, 2008 I'll hand over to the psy-corp here. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/128324-copy-record-help-please/#findComment-665896 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.