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

Link to comment
Share on other sites

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