php - INSERT INTO sql query is using variable string rather than field name -



php - INSERT INTO sql query is using variable string rather than field name -

getting confused surrounding insert into. should insert 3 fields table, userid, activatekey , isactivated.

the activatekey 25 letter randomly generated key such 63n20kw24ba1mlox34e8n2awv

the userid comes table , set auto_increment.

the isactivated 0 @ stage.

it seems quite simple insert statement

if (!mysqli_query($con,"insert activations (userid,activationkey,isactivated) values (".$userid.",".$activatekey.",'0')")) { echo("error description: " . mysqli_error($con)); }

however doesn't work when include $activatekey field. seek search string variable $activatekey column name. error is:

error description: unknown column '63n20kw24ba1mlox34e8n2awv' in 'field list'

of course of study there no such column 63n20kw24ba1mlox34e8n2awv, info i'm trying insert, hence why it's in values section. ideas why it's trying search column name?

edit clarify: var activatekey, column name activationkey

i set query in different variable avoid confusion, , php automatically substitutes variable names in strings in double quotes.

try this:

<?php $query = "insert activations (userid,activationkey,isactivated) values($userid,'$activatekey','0') if (!mysqli_query($con,$query) { echo("error description: " . mysqli_error($con)); }

php sql

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -