SamDOD Posted October 21, 2008 Share Posted October 21, 2008 using this code i am connecting to my data base and inserting login information from one table to another. function Log3(){ $Susername = $this->dbuser; $Spassword = $this->dbpass; $Shostname = $this->dbhost; $Sdatabase = $this->dbase; $dbhandle = mysql_connect($Shostname, $Susername, $Spassword) or die("Unable to connect to MySQL"); $selected = mysql_select_db($Sdatabase,$dbhandle) or die("Could not select Database"); $SQL2="INSERT INTO userlog4(userName, lastLog, ip, logtimeout)"; $SQL2.="SELECT (userName, lastLog, ip, logtimeout) "; $SQL2.="FROM myuser WHERE ".$this->tblID."='".$_SESSION['userID']."'"; $Send=mysql_query($SQL2); mysql_close($dbhandle); } It works fine, but.... i cant seem to do more than one col. If instead of (userName, lastLog, ip, logtimeout) i only put userName, or ip, by itself in both places it transfers fine but when i add another one it does not work. What am i doing wrong? Thank you for your time. Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/ Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 try putting parenthesis around the nested select: $SQL2="INSERT INTO userlog4(userName, lastLog, ip, logtimeout) "; $SQL2.="(SELECT (userName, lastLog, ip, logtimeout) "; $SQL2.="FROM myuser WHERE ".$this->tblID."='".$_SESSION['userID']."')"; Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-670946 Share on other sites More sharing options...
SamDOD Posted October 21, 2008 Author Share Posted October 21, 2008 Same thing happed. Nothing happens if i have two or more col but if i have one col it works. Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671003 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 try this and see if mysql is throwing any errors: $SQL2="INSERT INTO userlog4(userName, lastLog, ip, logtimeout) "; $SQL2.="(SELECT userName, lastLog, ip, logtimeout "; $SQL2.="FROM myuser WHERE ".$this->tblID."='".$_SESSION['userID']."')"; $Send=mysql_query($SQL2) or die("INSERT ERROR: ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671009 Share on other sites More sharing options...
SamDOD Posted October 21, 2008 Author Share Posted October 21, 2008 INSERT 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 ' lastLog, ip, logtimeout) FROM myuser WHERE ID='1')' at line 1 Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671018 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 can you do an echo $SQL2 and post the "generated" value of that string... Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671021 Share on other sites More sharing options...
SamDOD Posted October 21, 2008 Author Share Posted October 21, 2008 sorry had not uploaded the changed doc so i was getting nothing till i ran it again then got that error. Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671022 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 see this post: http://www.phpfreaks.com/forums/index.php/topic,222080.msg1020283.html#msg1020283 i removed parenthesis from around the list of field names. from the error you post, it looks like you haven't removed them yet... Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671026 Share on other sites More sharing options...
SamDOD Posted October 21, 2008 Author Share Posted October 21, 2008 It works, thank you i knew it was something stupid on my part that i was totally overlooking. Thank you very much! Link to comment https://forums.phpfreaks.com/topic/129412-solved-php-mysql-issue-with-insert-into/#findComment-671030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.