MikeFelker Posted October 27, 2010 Share Posted October 27, 2010 Hi and thank you in advance for helping me. Here is the code fragment: $sql="SELECT UserID,UserName FROM `UserValidation` WHERE UserID='".$_SESSION["UserID"]."'"; $rs=CustomQuery($sql); $RecData=db_fetch_array($rs); global $conn,$strUserValidation; $strSQLSave = "INSERT INTO RecruiterNames (UserID, UserName) values ("; $strSQLSave .= $RecData["UserID"].","; $strSQLSave .= chr(34).$RecData['UserName'].chr(34); $strSQLSave .= ")"; db_exec($strSQLSave,$conn); Here is the error I receive: php error happened Technical information Error type 256 Error description 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 '"")' at line 1 URL www.dealwithaces.com/ACESDB/register.php? Error file /home/debra/public_html/dealwithaces.com/ACESDB/include/dbconnection.php Error line 36 SQL query INSERT INTO RecruiterNames (UserID, UserName) values (,"") More info Call stack File: line Function Arguments #0. include/dbconnection.php:36 db_query 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #1. include/dbconnection.php:47 db_exec 1. INSERT INTO RecruiterNames (UserID, UserName) values (,""); 2. Resource id #10; #2. include/events.php:25 AfterSuccessfulRegistration 1. Array ( [userName] => bsbnick [Password] => kaos55 [userEmail] => [email protected] [GroupID] => 1 [userActive] => 0 ) ; #3. register.php:298 Global scope N/A I need two fields from UserValidation table (UserID and UserName) to be inserted into table RecruiterNames (UserID and UserName), but ONLY when GroupID = 3 Thank you again for your help. Mike Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/ Share on other sites More sharing options...
MikeFelker Posted October 27, 2010 Author Share Posted October 27, 2010 OK, someone from another forum was able to help me a bit, now there are no PHP errors. However, it is not inserting the data into the table - just nothing or NULL statements. Here is the corrected code: $sql="SELECT UserID,UserName FROM `UserValidation` WHERE UserID='".$_SESSION["UserID"]."'"; $rs=CustomQuery($sql); $RecData=db_fetch_array($rs); global $conn,$strUserValidation; $strSQLSave = "INSERT INTO RecruiterNames (UserID, UserName) values ("; $strSQLSave .= "'".$RecData["UserID"]."',"; $strSQLSave .= "'".$RecData['UserName']."'"; $strSQLSave .= ")"; db_exec($strSQLSave,$conn) I would truly appreciate someone's help on this. Mike Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/#findComment-1127274 Share on other sites More sharing options...
Vitamin Posted October 27, 2010 Share Posted October 27, 2010 What type of DB are you using? mysql? I've never used the db_exec function, but you can always try and echo your $strSQLSave string and see if the sytax is getting sent correctly. Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/#findComment-1127288 Share on other sites More sharing options...
MikeFelker Posted October 27, 2010 Author Share Posted October 27, 2010 What type of DB are you using? mysql? I've never used the db_exec function, but you can always try and echo your $strSQLSave string and see if the sytax is getting sent correctly. This is MySql, but I am using PHPRunner to create the database and coding smaller code fragments when needed. Unfortunately, nothing is showing up as a result of the $_SESSION["UserID"], so nothing is being written. That is my problem. The data is there, but this command is not working. Is there another way to get data from a table and then write it to another table? Mike Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/#findComment-1127307 Share on other sites More sharing options...
MikeFelker Posted October 27, 2010 Author Share Posted October 27, 2010 $sql="SELECT UserID FROM `UserValidation` WHERE GroupID=".$_SESSION["GroupID"]."=1"; printf("Selection SQL: %s\n", $sql); $rs=CustomQuery($sql); $RecData=db_fetch_array($rs); global $conn,$strUserValidation; $strSQLSave = "INSERT INTO RecruiterNames (UserID) values ("; $strSQLSave .= "'".$RecData['UserID']."'"; $strSQLSave .= ")"; db_exec($strSQLSave,$conn I know line 1 is wrong. How should it be formatted to work? I am trying to say that I want to set the value of UserID if the GroupID=1 Thanks. Mike Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/#findComment-1127323 Share on other sites More sharing options...
MikeFelker Posted October 28, 2010 Author Share Posted October 28, 2010 edit Quote Link to comment https://forums.phpfreaks.com/topic/217010-please-help-me-with-this-code-fragment-inserting-two-fields-into-another-table/#findComment-1127350 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.