Jump to content

[SOLVED] PHP / MySQL issue with INSERT INTO


SamDOD

Recommended Posts

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

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']."')";

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());

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

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.