php - Preparing insert statement for multiple columns -
php - Preparing insert statement for multiple columns -
i'm trying insert first name, lastly name, email , password db, of course of study want prepare statement first. searched around google , stack, couldn't find syntax inserting multiple columns, one. utilize in place of ? of prepare statement , bind_param().
here code:
if(!($sql = $link->prepare("insert users(fname, lname, email, password) value(fname=?, lname=?, email=?, password=?))){ echo "prepare failed: (" . $link->errno . ") " . $link->error; } $sql->bind_param('?', $fname); $sql->bind_param('?', $lname); $sql->bind_param('?', $email); $sql->bind_param('?', $hashpass); $sql->execute();
edit: possible? have each separately?
are using mysqli? looks are. if so, need phone call bind_param
1 time , in values
part of sql set comma separated question marks represent each column:
$query = "insert users(fname, lname, email, password) value(?, ?, ?, ?)"; if( !$sql = $link->prepare($query) ) { echo "prepare failed: (" . $link->errno . ") " . $link->error; } $sql->bind_param("ssss", $fname, $lname, $email, $hashpass); $sql->execute();
see mysqli bind_param
documentation more information.
p.s. cleaned code little , set sql in variable create cleaner.
php sql prepared-statement
Comments
Post a Comment