mysql - PHP mySQLi prepare fails with duplicate column '?' -


i attempting prepare statement mysqli

$stmt = $mysqli->prepare("insert high_priority `user` (`firstname`, `lastname`, `department`, `email`) select * (select ?,?,?,?) tmp not exists ( select `email` `user` `email` = ? ) limit 1;"); if (!$stmt) {     printf('errno: %d, error: %s', $mysqli->errno, $mysqli->error);     die; }  $statementreturncode = $stmt->bind_param("sssss", $ssofirstname, $ssolastname, $ssodepartment, $ssoemail, $ssoemail); if (!$statementreturncode) {     printf('errno: %d, error: %s', $stmt->errno, $stmt->error); }  $stmt->execute(); $stmt->close(); 

when run receive following error:

errno: 1060, error: duplicate column name '?' 

i've been able bind in fashion in past, i've never tried bind same column twice in different location in query (email).

how can use same value email in 2 different locations, or different issue?

to clarify being done query:

this query run frequently. if user exists in user table, no insert should attempted. if user not exist, user should added user table.

the user table has userid field auto-increments. if insert attempted user not added due unique constraint, auto-increment add 1 though insert did not occur. not exists query attempt mitigate issue.

example use:

insert `user` (     `user`.`firstname`,      `user`.`lastname`,      `user`.`department`,      `user`.`email`) select * (select 'john', 'doe', 'marketing', 'john.doe@mycorp.com') tmp not exists (     select `user`.`email`      `user`      `user`.`email` = 'john.doe@mycorp.com' ) limit 1; 

i have tested query , works had expected. issue i'm having changing query prepared statement php.

column names aren't string literals, don't bind column names

$stmt = $mysqli->prepare(sprint("insert high_priority `user` (`firstname`, `lastname`, `department`, `email`) select * (select '%s', '%s', '%s', '%s') tmp not exists ( select `email` `user` `email` = ? ) limit 1;"), $ssofirstname, $ssolastname, $ssodepartment, $ssoemail); if (!$stmt) {     printf('errno: %d, error: %s', $mysqli->errno, $mysqli->error);     die; }  $statementreturncode = $stmt->bind_param("s", $ssoemail); if (!$statementreturncode) {     printf('errno: %d, error: %s', $stmt->errno, $stmt->error); } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -