This topic is locked
[SOLVED]

  Still stuck - can someone find my error

10/27/2010 12:42:55 AM
PHPRunner General questions
K
karmacomposer author

Here's my code:
$sql="SELECT UserID,UserName FROM UserValidation WHERE GroupID=1";

$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);
===========================
Group ID=1 means GroupID=Recruiter (so, I am assuming, it is selecting the row as long as it is a Recruiter). At least, that is what I need. Only if the registrant selects Recruiter in a drop down (that gives a value of 1) will it write the two pieces of information to another table.
This WORKS except for one thing. I am trying to write the registrant's UserID and UserName and sending it to another table with fields UserID and UserName. Pretty straightforward.
When I try to register a recruiter, I get the following error:
Technical information

Error type 256

Error description Duplicate entry '68' for key 1

URL /ACESDB/register.php?

Error file /ACESDB/include/dbconnection.php

Error line 36

SQL query INSERT INTO RecruiterNames (UserID, UserName) values (68,"mikefelker")
It is trying to write the same UserID and UserName - the first one.
How do I get it to SELECT and INSERT INTO the current UserID and UserName (namely, the person signing up)?
Mike

K
karmacomposer author 10/27/2010

Support advised me on changing the 1st line to use the _$SESSION command, but I still get PHP errors.
Can someone check my work and see what is wrong:
$sql="SELECT UserID,UserName FROM UserValidation WHERE UserName='".$_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);

K
karmacomposer author 10/27/2010

I tried this:
$sql="SELECT UserID,UserName FROM UserValidation WHERE UserName=".chr(34).$_SESSION["UserID"].chr(34).";";
It did not work either.
That is the line that needs to work properly. All the others are fine.
I need to fix this today, so help is appreciated.
Mike

K
karmacomposer author 10/27/2010

OK, with some outside help, I now get no PHP errors, but it is not writing the proper data into the proper places.
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 .= "'".$RecData['UserName']."'";

$strSQLSave .= ")";

db_exec($strSQLSave,$conn)
I need the UserID and UserName from the current user that is registering (after they press the SAVE button) written to the UserValidation table (in the UserID and UserName fields).
This is in the AFTER SUCCESSFUL REGISTRATION event.
Mike

Sergey Kornilov admin 10/27/2010

You need to print your SQL queries on the web page using echo command to see if syntax is correct.

K
karmacomposer author 10/27/2010



You need to print your SQL queries on the web page using echo command to see if syntax is correct.


echo $RecData["UserID"];

echo $RecData["UserName"];
It goes too fast for me to see. Is there a pause command? I end up at the successful registration screen.
Mike

T
Tempus_Erus 10/28/2010



echo $RecData["UserID"];

echo $RecData["UserName"];
It goes too fast for me to see. Is there a pause command? I end up at the successful registration screen.
Mike


Hi,
Not the most ideal solution but you could try sleep(25); command. where 25 is seconds.
A

K
karmacomposer author 10/28/2010

Someone on a different forum suggested I use the print command. That worked.
However, the data is still not writing correctly.
Now trying this suggestion:
if ($_SESSION['GroupID'] == 1)

$sql="SELECT UserID,UserName FROM UserValidation WHERE GroupID=".chr(34).$_SESSION['GroupID'].chr(34);

printf("Selection SQL: %s\n", $sql);

$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)
The person who suggested this put brackets at the beginning of the $sql statement and closed it at the end, but PHPRunner kept giving me an error until I removed them.
Why is it that people have great suggestions and NONE of them are working.
Mike

Sergey Kornilov admin 10/28/2010

The last line of code is still truncated - there is no semicolon at the end.

K
karmacomposer author 10/28/2010



The last line of code is still truncated - there is no semicolon at the end.


Thank you. Yes. I closed it with a ;
I still get this error:
php error happened
Technical information

Error type 256

Error description Duplicate entry '68' for key 1

URL www.dealwithaces.com/ACESDB/RecruiterData_add.php?

Error file /home/debra/public_html/dealwithaces.com/ACESDB/include/dbconnection.php

Error line 36

SQL query INSERT INTO RecruiterNames (UserID,UserName) values ('68','mikefelker')

More info
It is trying to write the top row, which already exists in the RecruiterNames table (68,MikeFelker as values)
I need it to write the current row, not the 1st one. Unless it's trying to write all the rows.
I'm getting worn down. I don't have the money for it, but I am trying to find a way to afford some coding time with you guys.
Mike