Jump to content

Please help me with this code fragment - inserting two fields into another table


MikeFelker

Recommended Posts

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] => mike@world-class-multimedia.com [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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

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.